Some Questions about PHPExcel Charts

2020-04-20 12:23发布

问题:

I am using PHPExcel for generating charts in Excel Files. I have some question whoes answer I couldn't find even after lot of R&D those are

  1. How can I show data labels to chart?
  2. How can I control the width of bar charts?
  3. How can I customize colors of bar charts?

I tried to show labels with layout class like :

  $layout = new PHPExcel_Chart_Layout();
  $layout->setShowVal(TRUE);

But no success. I have also explored DataSeries class and Chart Class but couldn't find any solution. Any body here who have already done such tasks, Please guide.

Best Regards.

回答1:

With this:

$dataseriesLabels = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1),
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1),
);

$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
);
  1. you can define the dataseriesLabels to use in your chart
  2. PHPExcel set default Column Width
  3. PhpExcel Bar Chart


回答2:

Read my answer there may be it will help with charts and yes better to create what you need and than use it with load and save(as template)

PHPExcel removes chart style when template is loaded