Created work item: Updating excel file - Graph displaying fail

Topics: Developer Forum
Dec 5, 2014 at 12:13 PM

I am creating a excel file containing 3 worksheets and a graph in the first worksheet.
After closing the file, I open it again, complete some tables in the first worksheet and:
First: the graph I had before disappeared
Second: I have no possibility to design and display a new graph (no error showing up)
I must say that I read the information directly from the same page and edit at the same time. Meaning: I open my file, write the new informations, save them, write some others, save again and then make the work for the graph.

I already used my code to generate graphs on other pages and it was working...

This is part of my code to add the graph:

// Reload sheet to work with
$sheetInit = $objWorksheet->toArray(null, true, true, true);

// Name of each serie on the graph
$dataseriesLabels = array();
$position = '';
for($i=1; $i<sizeof($sheetInit[1]); $i++) {
    $position = 'Worksheet!$'.$alpha[$i].'$2';
    $dataseriesLabels[$i-1] = new PHPExcel_Chart_DataSeriesValues('String', $position, NULL, 1);

// x Axis values
$xAxisTickValues = array();

for($i=0; $i<sizeof($dataseriesLabels); $i++) {
    $xAxisTickValues[$i] = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$3:$A$8', NULL, 6);

// Series values
$dataSeriesValues = array();
for($i=1; $i<sizeof($sheetInit[1]); $i++) {
    $position = 'Worksheet!$'.$alpha[$i].'$3:$'.$alpha[$i].'$8';
    $dataSeriesValues[$i-1] = new PHPExcel_Chart_DataSeriesValues('Number', $position, NULL, 6);

$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART,   // plotType
    NULL,                                           // plotGrouping (Scatter charts don't have any grouping)
    range(0, count($dataSeriesValues)-1),           // plotOrder
    $dataseriesLabels,                              // plotLabel
    $xAxisTickValues,                               // plotCategory
    $dataSeriesValues,                              // plotValues
    NULL,                                           // smooth line
    PHPExcel_Chart_DataSeries::STYLE_LINEMARKER     // plotStyle

//  Set the series in the plot area
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
//  Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false);

$title = new PHPExcel_Chart_Title('Test Stacked Line Chart');
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');

//  Create the chart
$chart = new PHPExcel_Chart(
    'chart1',       // name
    $title,         // title
    $legend,        // legend
    $plotarea,      // plotArea
    true,           // plotVisibleOnly
    0,              // displayBlanksAs
    NULL,           // xAxisLabel
    $yAxisLabel     // yAxisLabel


//  Set the position where the chart should appear in the worksheet

//  Add the chart to the worksheet

$objWriter = PHPExcel_IOFactory::createWriter($objWritePHPExcel, 'Excel5');
Can somebody help me?

Thank you!
Dec 10, 2014 at 4:39 PM
Please, I really need this to work, could you help me?