Skip to content

Commit 31968fa

Browse files
committed
Merge branch 'develop' of https://github.com/Tom-Magill/PHPWord into develop_upstream
2 parents fb60865 + 1392426 commit 31968fa

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/PhpWord/Style/Chart.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class Chart extends AbstractStyle
5151
* @var array
5252
*/
5353
private $colors = array();
54+
55+
/**
56+
* Chart title
57+
*
58+
* @var string
59+
*/
60+
private $title = null;
61+
62+
/**
63+
* Chart legend visibility
64+
*
65+
* @var bool
66+
*/
67+
private $showLegend = false;
5468

5569
/**
5670
* A list of display options for data labels
@@ -220,6 +234,50 @@ public function setColors($value = array())
220234

221235
return $this;
222236
}
237+
238+
/**
239+
* Get the chart title
240+
*
241+
* @return string
242+
*/
243+
public function getTitle()
244+
{
245+
return $this->title;
246+
}
247+
248+
/**
249+
* Set the chart title
250+
*
251+
* @param string $value
252+
*/
253+
public function setTitle($value = null)
254+
{
255+
$this->title = $value;
256+
257+
return $this;
258+
}
259+
260+
/**
261+
* Get chart legend visibility
262+
*
263+
* @return bool
264+
*/
265+
public function getShowLegend()
266+
{
267+
return $this->showLegend;
268+
}
269+
270+
/**
271+
* Set chart legend visibility
272+
*
273+
* @param bool $value
274+
*/
275+
public function setShowLegend($value = false)
276+
{
277+
$this->showLegend = $value;
278+
279+
return $this;
280+
}
223281

224282
/*
225283
* Show labels for axis

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ private function writeChart(XMLWriter $xmlWriter)
105105
{
106106
$xmlWriter->startElement('c:chart');
107107

108-
$xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
109-
110108
$this->writePlotArea($xmlWriter);
111109

112110
$xmlWriter->endElement(); // c:chart
@@ -130,6 +128,36 @@ private function writePlotArea(XMLWriter $xmlWriter)
130128
$type = $this->element->getType();
131129
$style = $this->element->getStyle();
132130
$this->options = $this->types[$type];
131+
132+
$title = $style->getTitle();
133+
$showLegend = $style->getShowLegend();
134+
135+
//Chart title
136+
if($title){
137+
$xmlWriter->startElement('c:title');
138+
$xmlWriter->startElement('c:tx');
139+
$xmlWriter->startElement('c:rich');
140+
$xmlWriter->writeRaw('
141+
<a:bodyPr/>
142+
<a:lstStyle/>
143+
<a:p>
144+
<a:pPr>
145+
<a:defRPr/></a:pPr><a:r><a:rPr/><a:t>'.$title.'</a:t></a:r>
146+
<a:endParaRPr/>
147+
</a:p>');
148+
149+
$xmlWriter->endElement(); // c:rich
150+
$xmlWriter->endElement(); // c:tx
151+
$xmlWriter->endElement(); // c:title
152+
153+
}else{
154+
$xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
155+
}
156+
157+
//Chart legend
158+
if($showLegend){
159+
$xmlWriter->writeRaw('<c:legend><c:legendPos val="r"/></c:legend>');
160+
}
133161

134162
$xmlWriter->startElement('c:plotArea');
135163
$xmlWriter->writeElement('c:layout');

0 commit comments

Comments
 (0)