PHPExcel图表未绘制且未给出错误

时间:2018-07-11 09:45:28

标签: php phpexcel

根据https://ourcodeworld.com/articles/read/95/generated-excel-file-with-charts-using-phpexcel-get-corrupted-with-a-streamed-response-in-symfony-php的指导,我一直在尝试与PHPExcel一起绘制带有一些数据的图表

我的代码如下

$dataseriesLabels1 = array(
        new \PHPExcel_Chart_DataSeriesValues('String', '$C$6', NULL, 1)); //  Wastage

 $dataseriesLabels2 = array(
     new \PHPExcel_Chart_DataSeriesValues('String', '$D$6', NULL, 1)); //  Purchases

 $dataseriesLabels3 = array(
        new \PHPExcel_Chart_DataSeriesValues('String', '$E$1', NULL, 1) //  Sales
    );

    $xAxisTickValues = array(
        new \PHPExcel_Chart_DataSeriesValues('String', '$A$'.$firstRow.':$A$'.$rowCounter, NULL, 12) // Stock Dates
    );

    $dataSeriesValues1 = array(
        new \PHPExcel_Chart_DataSeriesValues('Number', '$C$'.$firstRow.':$C$'.$rowCounter, NULL, 12) //wastage
    );
    //echo $dataSeriesValues1;
    //die();
    //  Build the dataseries
    $series1 = new \PHPExcel_Chart_DataSeries(
            \PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
            \PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
            range(0, count($dataSeriesValues1) - 1), // plotOrder
            $dataseriesLabels1, // plotLabel
            $xAxisTickValues, // plotCategory
            $dataSeriesValues1                              // plotValues
    );
    //  Set additional dataseries parameters
    //      Make it a vertical column rather than a horizontal bar graph
    $series1->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

    $dataSeriesValues2 = array(
        new \PHPExcel_Chart_DataSeriesValues('Number', '$D$'.$firstRow.':$D$'.$rowCounter, NULL, 12));//purchases

     //  Build the dataseries
    $series2 = new \PHPExcel_Chart_DataSeries(
            \PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
            \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
            range(0, count($dataSeriesValues2) - 1), // plotOrder
            $dataseriesLabels2, // plotLabel
            NULL, // plotCategory
            $dataSeriesValues2                              // plotValues
    );

    $dataSeriesValues3 = array(
        new \PHPExcel_Chart_DataSeriesValues('Number', '$E$'.$firstRow.':$E$'.$rowCounter, NULL, 12));//sales



//  Build the dataseries
        $series3 = new \PHPExcel_Chart_DataSeries(
                \PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType
                \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
                range(0, count($dataSeriesValues3) - 1), // plotOrder
                $dataseriesLabels3, // plotLabel
                NULL, // plotCategory
                $dataSeriesValues3                              // plotValues
        );

//  Set the series in the plot area
        $plotarea = new \PHPExcel_Chart_PlotArea(NULL, array($series1, $series2, $series3));
    //  Set the chart legend
    $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);

    $title = new \PHPExcel_Chart_Title('Chart awesome');

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

    //  Set the position where the chart should appear in the worksheet
    $chart->setTopLeftPosition('F2');
    $chart->setBottomRightPosition('O16');

    //  Add the chart to the worksheet
    $objWorksheet->addChart($chart);

当我生成excel文件时,一切正常,但未绘制图表。我遍历了代码和示例,但看不到哪里出错了?

我很想念我吗?这只是图表的测试运行,因为格式会略有不同,但是我想了解机制的工作原理。

0 个答案:

没有答案