Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
fc1fec5
debug code
jaek-s Jan 12, 2018
ca459f2
bring back old way of writing text in chart series items
jaek-s Jan 12, 2018
0219161
add stacked bar and column charts
jaek-s Jan 12, 2018
11975d6
allow stacked bar and column charts to be added to documents
jaek-s Jan 12, 2018
4b50d9a
forgot a comma
jaek-s Jan 12, 2018
8d7e6e0
remove extra <c:v>'s on series element values
jaek-s Jan 12, 2018
3743a9a
possible fix for stack charts behaving strangely
jaek-s Jan 12, 2018
8b10157
potential stack chart layout fix
jaek-s Jan 12, 2018
3e5b8bc
move this attribute to its proper place
jaek-s Jan 12, 2018
bf6fa59
another possible fix for stack chart layouts
jaek-s Jan 12, 2018
1063377
Merge pull request #1 from SurveyGizmoOfficial/stackCharts
SurveyGizmoOfficial Jan 12, 2018
9fc07d5
add chart colors feature
jaek-s Jan 16, 2018
8202ce1
use the correct variable when getting chart colors
jaek-s Jan 16, 2018
200d625
add SurveyGizmo specific options to the Word chart writer
jaek-s Jan 16, 2018
dc50a11
Testing connection
Jan 16, 2018
78a178c
gross workaround to make stacked chart series items use different colors
jaek-s Jan 17, 2018
9252411
only remove a single chart color at a time
jaek-s Jan 17, 2018
d1c9cd0
use array_shift properly
jaek-s Jan 17, 2018
86bfa5b
change axis options for SG charts
jaek-s Jan 17, 2018
4894d24
remove broken code
jaek-s Jan 17, 2018
d82103d
use correct property values
jaek-s Jan 17, 2018
6abdcee
Merge branch 'develop' into chartColors
SurveyGizmoOfficial Jan 17, 2018
5bce835
Merge pull request #2 from SurveyGizmoOfficial/chartColors
SurveyGizmoOfficial Jan 17, 2018
1902e55
Added variables and getters for xAxisLabels and yAxisLabels
Jan 17, 2018
fa0a59e
removing debugs for testing
Jan 17, 2018
ac4d074
Fixed a syntax error
Jan 17, 2018
a2e268f
added a debug statement
Jan 17, 2018
9a6c8e4
more debug logs
Jan 17, 2018
30916e0
added the style object to writeAxis
Jan 17, 2018
f6b6b4e
added debug statement for axisType
Jan 17, 2018
0e8ef73
writeAxis now reads from the style object
Jan 17, 2018
5857cfd
adding preliminary chart axis title functionality to XMLwriter
Jan 18, 2018
bff8742
simplified the title writer
Jan 18, 2018
31a5378
added more specific xml for axis title
Jan 18, 2018
981a461
debugging
Jan 18, 2018
7168c87
expiriment to test if changing series names is possible
jaek-s Jan 18, 2018
fa4c6e1
fixed syntax error
Jan 18, 2018
9429a20
removed some comments
Jan 18, 2018
7e1fe8f
fix merge issues
jaek-s Jan 18, 2018
d4cf322
do it RAW
jaek-s Jan 18, 2018
575051b
do it RAW for real
jaek-s Jan 18, 2018
bbba1f8
added getters and setters for Axis titles
Jan 18, 2018
260e287
added use of getter in the writer
Jan 18, 2018
d839e0f
make naming series possible
jaek-s Jan 18, 2018
e390c69
fixed typo
Jan 18, 2018
f5f9f67
syntax error fixes and renaming for clarity
Jan 18, 2018
241dca6
naming change
Jan 18, 2018
e8e401f
abstracted title writing out into a new function
Jan 18, 2018
e387616
add data label options to chart styles, and another quick test
jaek-s Jan 18, 2018
f1adb64
actually write data label options
jaek-s Jan 18, 2018
1893252
unsetting initial titles. if blank they will be omitted.
Jan 18, 2018
79a8061
make setDataLabelOptions return
jaek-s Jan 18, 2018
1cc17ec
Merge pull request #3 from SurveyGizmoOfficial/seriesNames
SurveyGizmoOfficial Jan 18, 2018
8c3b352
Updated naming for clarity
Jan 18, 2018
10a870e
updating wording
Jan 18, 2018
db2428c
updated a comment
Jan 18, 2018
59ae499
Merge branch 'develop' of https://github.com/SurveyGizmoOfficial/PHPW…
Jan 18, 2018
ee90b45
changed setters to return this.
Jan 18, 2018
44e00b3
Merge pull request #4 from SurveyGizmoOfficial/axis-labels
SurveyGizmoOfficial Jan 18, 2018
6a497e8
added tests for Charts
Jan 31, 2018
e12cb52
edited tests with descriptions
Feb 1, 2018
3a8ebb8
added percent_stacked to available types array
blakenetz Mar 1, 2018
4efd88e
apply color hack to 100% stacked bar
blakenetz Mar 1, 2018
3919560
used case insensitive string matching
blakenetz Mar 1, 2018
f7094b1
Merge pull request #5 from SurveyGizmoOfficial/tests
SurveyGizmoOfficial Mar 14, 2018
f119724
Make tick mark and tick label positions configurable
Mar 14, 2018
7c6d3c5
I accidentally a semicolon
Mar 14, 2018
178dc74
Merge pull request #6 from SurveyGizmoOfficial/label-positions
SurveyGizmoOfficial Mar 14, 2018
3ce27cd
fetch the latest from upstream
Mar 14, 2018
7fa341f
accidentally removed a comment's end
Mar 14, 2018
8ba5820
Merge pull request #7 from SurveyGizmoOfficial/merge-updates
SurveyGizmoOfficial Mar 28, 2018
f5eb352
formatting
Apr 4, 2018
fb6800e
fix some style stuff
Apr 4, 2018
cc450e5
fix comments to match the code
Apr 4, 2018
9a7cf4b
fix comments to match the code... again
Apr 4, 2018
179b614
merge upstream and fix conflicts
Apr 4, 2018
26f3ce7
Merge branch 'develop' into documentation
Apr 4, 2018
a257243
Merge branch 'develop' into surveygizmo
troosan Apr 13, 2018
2c337b1
scrutinizer fixes
troosan Apr 19, 2018
baab3c9
update changelog
troosan Apr 19, 2018
d3cc363
Merge remote-tracking branch 'upstream/develop' into develop_upstream
troosan Apr 19, 2018
d7118a0
restore radar
troosan Apr 19, 2018
41cbc5e
fix radar chart
troosan Apr 25, 2018
3f0c59f
Merge branch 'develop' of https://github.com/PHPOffice/PHPWord into d…
troosan Apr 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ v0.15.0 (?? ??? 2018)
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
- Added parsing of internal links in HTML reader @lalop #1336
- Several improvements to charts @JAEK-S #1332

### Fixed
- Fix reading of docx default style - @troosan #1238
Expand Down
4 changes: 2 additions & 2 deletions samples/Sample_32_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
$section->addTitle('2D charts', 1);
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));

$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar');
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$threeSeries = array('bar', 'line');
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
Expand Down
16 changes: 11 additions & 5 deletions src/PhpWord/Element/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Chart extends AbstractElement
* @param array $categories
* @param array $values
* @param array $style
* @param null|mixed $seriesName
*/
public function __construct($type, $categories, $values, $style = null)
public function __construct($type, $categories, $values, $style = null, $seriesName = null)
{
$this->setType($type);
$this->addSeries($categories, $values);
$this->addSeries($categories, $values, $seriesName);
$this->style = $this->setNewStyle(new ChartStyle(), $style, true);
}

Expand All @@ -86,7 +87,7 @@ public function getType()
*/
public function setType($value)
{
$enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter');
$enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter');
$this->type = $this->setEnumVal($value, $enum, 'pie');
}

Expand All @@ -95,10 +96,15 @@ public function setType($value)
*
* @param array $categories
* @param array $values
* @param null|mixed $name
*/
public function addSeries($categories, $values)
public function addSeries($categories, $values, $name = null)
{
$this->series[] = array('categories' => $categories, 'values' => $values);
$this->series[] = array(
'categories' => $categories,
'values' => $values,
'name' => $name,
);
}

/**
Expand Down
212 changes: 212 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,60 @@ class Chart extends AbstractStyle
private $is3d = false;

/**
* A list of colors to use in the chart
*
* @var array
*/
private $colors = array();

/**
* A list of display options for data labels
*
* @var array
*/
private $dataLabelOptions = array(
'showVal' => true, // value
'showCatName' => true, // category name
'showLegendKey' => false, //show the cart legend
'showSerName' => false, // series name
'showPercent' => false,
'showLeaderLines' => false,
'showBubbleSize' => false,
);

/**
* A string that tells the writer where to write chart labels or to skip
* "nextTo" - sets labels next to the axis (bar graphs on the left) (default)
* "low" - labels on the left side of the graph
* "high" - labels on the right side of the graph
*
* @var string
*/
private $categoryLabelPosition = 'nextTo';

/**
* A string that tells the writer where to write chart labels or to skip
* "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default)
* "low" - labels are below the graph
* "high" - labels above the graph
*
* @var string
*/
private $valueLabelPosition = 'nextTo';

/**
* @var string
*/
private $categoryAxisTitle;

/**
* @var string
*/
private $valueAxisTitle;

private $majorTickMarkPos = 'none';

/*
* Show labels for axis
*
* @var bool
Expand Down Expand Up @@ -146,6 +200,28 @@ public function set3d($value = true)
}

/**
* Get the list of colors to use in a chart.
*
* @return array
*/
public function getColors()
{
return $this->colors;
}

/**
* Set the colors to use in a chart.
*
* @param array $value a list of colors to use in the chart
*/
public function setColors($value = array())
{
$this->colors = $value;

return $this;
}

/*
* Show labels for axis
*
* @return bool
Expand All @@ -169,6 +245,31 @@ public function setShowAxisLabels($value = true)
}

/**
* get the list of options for data labels
*
* @return array
*/
public function getDataLabelOptions()
{
return $this->dataLabelOptions;
}

/**
* Set values for data label options.
* This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones.
*
* @param array $values [description]
*/
public function setDataLabelOptions($values = array())
{
foreach (array_keys($this->dataLabelOptions) as $option) {
if (isset($values[$option])) {
$this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]);
}
}
}

/*
* Show Gridlines for Y-Axis
*
* @return bool
Expand All @@ -192,6 +293,117 @@ public function setShowGridY($value = true)
}

/**
* Get the categoryLabelPosition setting
*
* @return string
*/
public function getCategoryLabelPosition()
{
return $this->categoryLabelPosition;
}

/**
* Set the categoryLabelPosition setting
* "none" - skips writing labels
* "nextTo" - sets labels next to the (bar graphs on the left)
* "low" - labels on the left side of the graph
* "high" - labels on the right side of the graph
*
* @param mixed $labelPosition
* @return self
*/
public function setCategoryLabelPosition($labelPosition)
{
$enum = array('nextTo', 'low', 'high');
$this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition);

return $this;
}

/**
* Get the valueAxisLabelPosition setting
*
* @return string
*/
public function getValueLabelPosition()
{
return $this->valueLabelPosition;
}

/**
* Set the valueLabelPosition setting
* "none" - skips writing labels
* "nextTo" - sets labels next to the value
* "low" - sets labels are below the graph
* "high" - sets labels above the graph
*
* @param string
* @param mixed $labelPosition
*/
public function setValueLabelPosition($labelPosition)
{
$enum = array('nextTo', 'low', 'high');
$this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition);

return $this;
}

/**
* Get the categoryAxisTitle
* @return string
*/
public function getCategoryAxisTitle()
{
return $this->categoryAxisTitle;
}

/**
* Set the title that appears on the category side of the chart
* @param string $axisTitle
*/
public function setCategoryAxisTitle($axisTitle)
{
$this->categoryAxisTitle = $axisTitle;

return $this;
}

/**
* Get the valueAxisTitle
* @return string
*/
public function getValueAxisTitle()
{
return $this->valueAxisTitle;
}

/**
* Set the title that appears on the value side of the chart
* @param string $axisTitle
*/
public function setValueAxisTitle($axisTitle)
{
$this->valueAxisTitle = $axisTitle;

return $this;
}

public function getMajorTickPosition()
{
return $this->majorTickMarkPos;
}

/**
* set the position for major tick marks
* @param string $position [description]
*/
public function setMajorTickPosition($position)
{
$enum = array('in', 'out', 'cross', 'none');
$this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
}

/*
* Show Gridlines for X-Axis
*
* @return bool
Expand Down
Loading