Skip to content

Commit d42854d

Browse files
committed
chart doc/sample/code comments
1 parent 6f1b189 commit d42854d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

docs/styles.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Available Chart style options:
201201
- ``colors``. A list of colors to use in the chart.
202202
- ``title``. The title for the chart.
203203
- ``showLegend``. Show legend, *true* or *false*.
204+
- ``LegendPosition``. Legend position, *r* (default), *b*, *t*, *l* or *tr*.
204205
- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
205206
- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
206207
- ``categoryAxisTitle``. The title for the category axis.

samples/Sample_32_Chart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
$series3 = array(8, 3, 2, 5, 4);
2626
$showGridLines = false;
2727
$showAxisLabels = false;
28+
$showLegend = true;
29+
$legendPosition = 't';
30+
// r = right, l = left, t = top, b = bottom, tr = top right
2831

2932
foreach ($chartTypes as $chartType) {
3033
$section->addTitle(ucfirst($chartType), 2);
@@ -33,6 +36,8 @@
3336
$chart->getStyle()->setShowGridX($showGridLines);
3437
$chart->getStyle()->setShowGridY($showGridLines);
3538
$chart->getStyle()->setShowAxisLabels($showAxisLabels);
39+
$chart->getStyle()->setShowLegend($showLegend);
40+
$chart->getStyle()->setLegendPosition($legendPosition);
3641
if (in_array($chartType, $twoSeries)) {
3742
$chart->addSeries($categories, $series2);
3843
}

src/PhpWord/Style/Chart.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class Chart extends AbstractStyle
6767
private $showLegend = false;
6868

6969
/**
70-
* Chart legend Position.
70+
* Chart legend Position.
71+
* Possible values are 'r', 't', 'b', 'l', 'tr'
7172
*
7273
* @var string
7374
*/
@@ -240,6 +241,7 @@ public function getColors()
240241
* Set the colors to use in a chart.
241242
*
242243
* @param array $value a list of colors to use in the chart
244+
* @return self
243245
*/
244246
public function setColors($value = array())
245247
{
@@ -262,6 +264,7 @@ public function getTitle()
262264
* Set the chart title
263265
*
264266
* @param string $value
267+
* @return self
265268
*/
266269
public function setTitle($value = null)
267270
{
@@ -284,6 +287,7 @@ public function isShowLegend()
284287
* Set chart legend visibility
285288
*
286289
* @param bool $value
290+
* @return self
287291
*/
288292
public function setShowLegend($value = false)
289293
{
@@ -312,11 +316,13 @@ public function getLegendPosition()
312316
*
313317
* default: right
314318
*
315-
* @param bool $value
319+
* @param string $legendPosition
320+
* @return self
316321
*/
317-
public function setLegendPosition($value = 'r')
322+
public function setLegendPosition($legendPosition = 'r')
318323
{
319-
$this->legendPosition = $value;
324+
$enum = array('r', 'b', 't', 'l', 'tr');
325+
$this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition);
320326

321327
return $this;
322328
}
@@ -364,7 +370,10 @@ public function setDataLabelOptions($values = array())
364370
{
365371
foreach (array_keys($this->dataLabelOptions) as $option) {
366372
if (isset($values[$option])) {
367-
$this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]);
373+
$this->dataLabelOptions[$option] = $this->setBoolVal(
374+
$values[$option],
375+
$this->dataLabelOptions[$option]
376+
);
368377
}
369378
}
370379
}

0 commit comments

Comments
 (0)