I am generating a line chart using the example from Github library.
What i want to have is the option to set few custom styles for each of the lines in the chart, as we do manually in the excel sheet like:
Select Line in the chart, Format Data Series, then:
How can i set the above three options for the lines generated in the line chart? So far, here is my code to set the layout and data series for the chart:
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART,
PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
$layout1 = new PHPExcel_Chart_Layout();
$layout1->setShowVal(TRUE);
$plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series));
Can someone provide a hint, as i can't find it in the example.
In the file PHPExcel/Chart/Renderer/jpgraph.php
on line 287:
$marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
Change this into
$marker = 'none';
To get rid of the markers, note that this is a bit hacky fix, normally it loops trough all markers and there is no functionality made in the tool to set the marker yourself. (that is why you cannot find it in the examples)
You can also remove or edit the code at Excel2007/Chart.php
line 792, here you can see the if ($plotSeriesMarker)
code, change it to "none"
or just delete this part.
In the file PHPExcel/Writer/Excel2007/Chart.php
At line 781 in function _writePlotGroup
you can see the line plotting code
if ($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
$objWriter->startElement('c:spPr');
$objWriter->startElement('a:ln');
$objWriter->writeAttribute('w', 12700);
$objWriter->endElement();
$objWriter->endElement();
}
Here you can change the width by using for example:
$objWriter->writeAttribute('w', '40000');
The construct function of PHPExcel_Chart_DataSeries
is
/**
* Create a new PHPExcel_Chart_DataSeries
*/
public function __construct($plotType = null, $plotGrouping = null, $plotOrder = array(), $plotLabel = array(), $plotCategory = array(), $plotValues = array(), $smoothLine = null, $plotStyle = null)
So after your $dataSeriesValues
you can define a smoothline
and a plotStyle
value.
Passing true
to the smoothline
parameter gives you a smooth line style.
If for some reason that does not work, in the Chart.php
you can find on line 272
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
Change this to
$objWriter->writeAttribute('val', 1 );
And it should work for sure.
At the time of this response the solution to your first question; Marker Options > None is simple and doesn't involve modifying base code. When creating $dataSeriesValues
objects(line 86) you can define which type of marker you want or 'none'.
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4, array(), 'none'),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4, array(), 'none'),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4, array(), 'none'),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With