PHPPowerpoint: Grid lines + Custom chart line colors + Y-axis designation

I am using the following code to create a chart using PHP Powerpoint .

$currentSlide = createTemplatedSlide($objPHPPowerPoint); $seriesData = array('ABC'=>97,'BCD'=>97,'CDE'=>97,'DEF'=>97,'EFG'=>97,'FGH'=>97); $lineChart = new PHPPowerPoint_Shape_Chart_Type_Line(); $series = new PHPPowerPoint_Shape_Chart_Series('Benchmark', $seriesData); $series->setShowSeriesName(false); $lineChart->addSeries($series); $shape = $currentSlide->createChartShape(); $shape->setName('Benchmark') ->setResizeProportional(false) ->setHeight(480) ->setWidth(940) ->setOffsetX(10) ->setOffsetY(100); $shape->getShadow()->setVisible(false) $shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_GRADIENT_LINEAR) ->setStartColor(new PHPPowerPoint_Style_Color('ddd9c3')) ->setEndColor(new PHPPowerPoint_Style_Color('ddd9c3')) ->setRotation(270); $shape->getBorder()->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE); $shape->getTitle()->setText(''); $shape->getTitle()->getFont()->setItalic(true); $shape->getPlotArea()->setType($lineChart); $shape->getView3D()->setRotationX(30); $shape->getView3D()->setPerspective(30); 

The graph comes out as expected (a screenshot is attached), but I would like to configure 3 things:

  • Add mesh grids to the chart (maybe?)
  • Specify the color of the chart line instead of the default. There will consist of several graphic lines in one graphic. Therefore, I need to specify a custom color for each line.
  • Mark the Y axis (currently empty)

Screenshot

Chart

+4
source share
1 answer

I found 2 versions of this library on the Internet. One is from github and the other is codeplex.One on Github definitely looks newer, but it lacks documentation of any type. Codeplex is dated, but actually has code samples.

tl; dr - No (in my testing anyway), No and No.

Long version

Looking through the code and looking at the generated XML, I noticed several things:

  • In Powerpoint 2013, the Y axis (value axis) is not displayed in the generated file, but saving the file after opening it led to the appearance of the Y axis. I see label marks in XML, but something is preventing me from displaying it.

Generated XML (charts / chart1.xml after unpacking the generated .pptx file):

  <c:valAx> <c:axId val="52749440"/> <c:scaling> <c:orientation val="minMax"/> </c:scaling> <c:axPos val="l"/> <c:numFmt formatCode="" sourceLinked="0"/> <c:majorTickMark val="none"/> <c:tickLblPos val="nextTo"/> <c:txPr> <a:bodyPr/> <a:lstStyle/> <a:p> <a:pPr> <a:defRPr/> </a:pPr> <a:r> <a:rPr lang="en-US" dirty="0"/> <a:t>Y Axis!</a:t> </a:r> <a:endParaRPr lang="en-US" dirty="0"/> </a:p> </c:txPr> <c:crossAx val="52743552"/> <c:crosses val="autoZero"/> <c:crossBetween val="between"/> </c:valAx> 

I am setting Axis labels by adding the following lines:

 $shape->getPlotArea()->getAxisX()->setTitle('X Axis!'); $shape->getPlotArea()->getAxisY()->setTitle('Y Axis!'); 

after this line in the script:

 $shape->getPlotArea()->setType($lineChart); 
  • Grid lines and line color seem possible, but there are no support methods in the current class.

The last available Powerpoint writer classes date back to 2007, which are pretty dated. You may need to update the XML structure and add some additional features. I will review some documents in OOXML format and see how easy it would be to add them without rewriting the writer classes from scratch.

+1
source

Source: https://habr.com/ru/post/1482709/


All Articles