4

I'm using the following code to create a chart with the PHP Powerpoint library.

$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 chart is coming out as expected (screenshot attached), but I would like to customize 3 things:

  • Add gridlines to the chart (Possible ?)
  • Specify the chart line color instead of using the default ones. There are going to be multiple chart lines in a single chart. So I need to specify a custom color for each line.
  • Label the Y-axis (At present it's blank)

Screenshot

Chart

asprin
  • 9,579
  • 12
  • 66
  • 119

1 Answers1

1

I found 2 versions of this library online. One in github and the other on codeplex. The one on Github definitely looks newer, but is lacking documentation of any type. Codeplex is dated, but actually has code samples.

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

Long version

From browsing through the code and reviewing the XML it creates I noticed a few things:

  1. In Powerpoint 2013, the Y Axis (Value Axis) doesn't show up in the generated file, but saving the file once I've opened it resulted in the Y Axis appearing. I see the axis labels in the XML but something is preventing it from being displayed .

Generated XML (charts/chart1.xml after unzipping 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 set the Axis labels by adding these lines:

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

after this line in your script:

$shape->getPlotArea()->setType($lineChart);
  1. The gridlines and line color seem to be possible, but there aren't methods in the current class to support them.

The last Powerpoint writer classes available are for 2007, which are quite a bit out of date. The XML structure probably needs to be updated and some additional features added. I'll take a look at some docs on the OOXML format and see how easy it would be to add these in without rewriting the writer classes from scratch.

Chris Rasco
  • 2,713
  • 1
  • 18
  • 22