phpphpexcelphpexcelreader

PHPExcel Display Charts not working


I am trying to display an Excel File generated using PHPExcel on a webpage. The image consists of a bar graph. I try to display it using

$objPHPExcel = new PHPExcel ();
$objWorksheet = $objPHPExcel->getActiveSheet ();
$objWorksheet->fromArray ( $data_array );
$dataseriesLabels = array (
    new PHPExcel_Chart_DataSeriesValues ( 'String', 'Worksheet!$A$2', null, 3 ) ,
    new PHPExcel_Chart_DataSeriesValues ( 'String', 'Worksheet!$A$3', null, 3 ),
    new PHPExcel_Chart_DataSeriesValues ( 'String', 'Worksheet!$A$4', null, 3 )
); 

$xAxisTickValues = array (
    new PHPExcel_Chart_DataSeriesValues ( 'String', 'Worksheet!$B$1:$F$1', null, 3 ), 
);

$dataSeriesValues = array (
    new PHPExcel_Chart_DataSeriesValues ( 'Number', 'Worksheet!$B$2:$G$2', null, 6 ),
    new PHPExcel_Chart_DataSeriesValues ( 'Number', 'Worksheet!$B$3:$G$3', null, 6 ),
    new PHPExcel_Chart_DataSeriesValues ( 'Number', 'Worksheet!$B$4:$G$4', null, 6 )

);

$series = new PHPExcel_Chart_DataSeries ( PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range ( 0, count ( $dataSeriesValues ) - 1 ), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues ); // plotValues

$series->setPlotDirection ( PHPExcel_Chart_DataSeries::DIRECTION_COL );
$plotarea = new PHPExcel_Chart_PlotArea ( null, array ( $series) );
$legend = new PHPExcel_Chart_Legend ( PHPExcel_Chart_Legend::POSITION_RIGHT, null, false );
$title = new PHPExcel_Chart_Title ( 'Vendor Comparison Chart' );
$yAxisLabel = new PHPExcel_Chart_Title ( 'Rating' );

$chart = new PHPExcel_Chart ( 'chart1', $title, $legend,$plotarea,true, 0, null,$yAxisLabel ); 


$chart->setTopLeftPosition ( 'A7' );
$chart->setBottomRightPosition ( 'Q28' );

 $objWorksheet->addChart ( $chart );
$objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'HTML' );
$objWriter->setIncludeCharts ( TRUE );
$objWriter->save ( "php://output" );

This is able to output just the table data but does not show the chart in the excel file. Any help will be much appreciated because I am a beginner in PHPExcel. How can I display the chart?


Solution

  • The jpgraph renderer was not configured properly