Skip to content

Commit a8d1775

Browse files
committed
Merge remote-tracking branch 'FrankMeyer/develop' into develop
2 parents 2c5970a + a652847 commit a8d1775

File tree

3 files changed

+104
-3
lines changed

3 files changed

+104
-3
lines changed

samples/Sample_32_Chart.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
$series1 = array(1, 3, 2, 5, 4);
2424
$series2 = array(3, 1, 7, 2, 6);
2525
$series3 = array(8, 3, 2, 5, 4);
26+
$showGridLines = false;
27+
$showAxisLabels = false;
2628

2729
foreach ($chartTypes as $chartType) {
2830
$section->addTitle(ucfirst($chartType), 2);
2931
$chart = $section->addChart($chartType, $categories, $series1);
3032
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
33+
$chart->getStyle()->setShowGridX($showGridLines);
34+
$chart->getStyle()->setShowGridY($showGridLines);
35+
$chart->getStyle()->setShowAxisLabels($showAxisLabels);
3136
if (in_array($chartType, $twoSeries)) {
3237
$chart->addSeries($categories, $series2);
3338
}
@@ -44,7 +49,8 @@
4449

4550
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
4651
$multiSeries = array('bar', 'column', 'line', 'area');
47-
$style = array('width' => Converter::cmToEmu(5), 'height' => Converter::cmToEmu(4), '3d' => true);
52+
$style = array('width' => Converter::cmToEmu(5), 'height' => Converter::cmToEmu(4), '3d' => true,
53+
'showAxisLabels' => $showAxisLabels, 'showGridX' => $showGridLines, 'showGridY' => $showGridLines);
4854
foreach ($chartTypes as $chartType) {
4955
$section->addTitle(ucfirst($chartType), 2);
5056
$chart = $section->addChart($chartType, $categories, $series1, $style);

src/PhpWord/Style/Chart.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ class Chart extends AbstractStyle
4545
*/
4646
private $is3d = false;
4747

48+
/**
49+
* Show labels for axis
50+
*
51+
* @var bool
52+
*/
53+
private $showAxisLabels = false;
54+
55+
/**
56+
* Show Gridlines for Y-Axis
57+
*
58+
* @var bool
59+
*/
60+
private $gridY = false;
61+
62+
/**
63+
* Show Gridlines for X-Axis
64+
*
65+
* @var bool
66+
*/
67+
private $gridX = false;
68+
4869
/**
4970
* Create a new instance
5071
*
@@ -123,4 +144,73 @@ public function set3d($value = true)
123144

124145
return $this;
125146
}
147+
148+
/**
149+
* Show labels for axis
150+
*
151+
* @return bool
152+
*/
153+
public function showAxisLabels()
154+
{
155+
return $this->showAxisLabels;
156+
}
157+
158+
/**
159+
* Set show Gridlines for Y-Axis
160+
*
161+
* @param bool $value
162+
* @return self
163+
*/
164+
public function setShowAxisLabels($value = true)
165+
{
166+
$this->showAxisLabels = $this->setBoolVal($value, $this->showAxisLabels);
167+
168+
return $this;
169+
}
170+
171+
/**
172+
* Show Gridlines for Y-Axis
173+
*
174+
* @return bool
175+
*/
176+
public function showGridY()
177+
{
178+
return $this->gridY;
179+
}
180+
181+
/**
182+
* Set show Gridlines for Y-Axis
183+
*
184+
* @param bool $value
185+
* @return self
186+
*/
187+
public function setShowGridY($value = true)
188+
{
189+
$this->gridY = $this->setBoolVal($value, $this->gridY);
190+
191+
return $this;
192+
}
193+
194+
/**
195+
* Show Gridlines for X-Axis
196+
*
197+
* @return bool
198+
*/
199+
public function showGridX()
200+
{
201+
return $this->gridX;
202+
}
203+
204+
/**
205+
* Set show Gridlines for X-Axis
206+
*
207+
* @param bool $value
208+
* @return self
209+
*/
210+
public function setShowGridX($value = true)
211+
{
212+
$this->gridX = $this->setBoolVal($value, $this->gridX);
213+
214+
return $this;
215+
}
126216
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values)
255255
*/
256256
private function writeAxis(XMLWriter $xmlWriter, $type)
257257
{
258+
$style = $this->element->getStyle();
258259
$types = array(
259260
'cat' => array('c:catAx', 1, 'b', 2),
260261
'val' => array('c:valAx', 2, 'l', 1),
@@ -272,10 +273,14 @@ private function writeAxis(XMLWriter $xmlWriter, $type)
272273
$xmlWriter->writeElementBlock('c:delete', 'val', 0);
273274
$xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'none');
274275
$xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none');
275-
$xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'none'); // nextTo
276+
if ($style->showAxisLabels()) {
277+
$xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo');
278+
} else {
279+
$xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'none');
280+
}
276281
$xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero');
277282
}
278-
if (isset($this->options['radar'])) {
283+
if (isset($this->options['radar']) || ($type == "cat" && $style->showGridX()) || ($type == "val" && $style->showGridY())) {
279284
$xmlWriter->writeElement('c:majorGridlines');
280285
}
281286

0 commit comments

Comments
 (0)