Skip to content

Commit 1063377

Browse files
Merge pull request #1 from SurveyGizmoOfficial/stackCharts
Stack charts
2 parents 4a530d1 + bf6fa59 commit 1063377

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/PhpWord/Element/Chart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getType()
8686
*/
8787
public function setType($value)
8888
{
89-
$enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter');
89+
$enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'column', 'stacked_column', 'area', 'radar', 'scatter');
9090
$this->type = $this->setEnumVal($value, $enum, 'pie');
9191
}
9292

src/PhpWord/Writer/Word2007/Part/Chart.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ class Chart extends AbstractPart
4141
* @var array
4242
*/
4343
private $types = array(
44-
'pie' => array('type' => 'pie', 'colors' => 1),
45-
'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true),
46-
'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar'),
47-
'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col'),
48-
'line' => array('type' => 'line', 'colors' => 0, 'axes' => true),
49-
'area' => array('type' => 'area', 'colors' => 0, 'axes' => true),
50-
'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true),
51-
'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true),
44+
'pie' => array('type' => 'pie', 'colors' => 1),
45+
'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true),
46+
'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'),
47+
'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'),
48+
'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'),
49+
'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'),
50+
'line' => array('type' => 'line', 'colors' => 0, 'axes' => true),
51+
'area' => array('type' => 'area', 'colors' => 0, 'axes' => true),
52+
'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true),
53+
'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true),
5254
);
5355

5456
/**
@@ -145,7 +147,7 @@ private function writePlotArea(XMLWriter $xmlWriter)
145147
}
146148
if (isset($this->options['bar'])) {
147149
$xmlWriter->writeElementBlock('c:barDir', 'val', $this->options['bar']); // bar|col
148-
$xmlWriter->writeElementBlock('c:grouping', 'val', 'clustered'); // 3d; standard = percentStacked
150+
$xmlWriter->writeElementBlock('c:grouping', 'val', $this->options['grouping']); // 3d; standard = percentStacked
149151
}
150152
if (isset($this->options['radar'])) {
151153
$xmlWriter->writeElementBlock('c:radarStyle', 'val', $this->options['radar']);
@@ -157,6 +159,8 @@ private function writePlotArea(XMLWriter $xmlWriter)
157159
// Series
158160
$this->writeSeries($xmlWriter, isset($this->options['scatter']));
159161

162+
$xmlWriter->writeElementBlock('c:overlap', 'val', '100');
163+
160164
// Axes
161165
if (isset($this->options['axes'])) {
162166
$xmlWriter->writeElementBlock('c:axId', 'val', 1);
@@ -230,14 +234,19 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values)
230234

231235
$xmlWriter->startElement($itemType);
232236
$xmlWriter->startElement($itemLit);
237+
$xmlWriter->writeElementBlock('c:ptCount', 'val', count($values));
233238

234239
$index = 0;
235240
foreach ($values as $value) {
236241
$xmlWriter->startElement('c:pt');
237242
$xmlWriter->writeAttribute('idx', $index);
238-
$xmlWriter->startElement('c:v');
239-
$this->writeText($value);
240-
$xmlWriter->endElement(); // c:v
243+
if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) {
244+
$xmlWriter->writeElement('c:v', $value);
245+
} else {
246+
$xmlWriter->startElement('c:v');
247+
$xmlWriter->writeRaw($value);
248+
$xmlWriter->endElement(); // c:v
249+
}
241250
$xmlWriter->endElement(); // c:pt
242251
$index++;
243252
}

0 commit comments

Comments
 (0)