2

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.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
  • You cannot easily modify these items, however, if you look into `PHPExcel/Classes/Writer/Excel2007/Chart.php, you can make hard-coded changes within that file to alter the format for ALL charts created with PHPExcel. – IIIOXIII Oct 16 '13 at 07:08
  • Create a graph which you want in excel and you can use Open XML SDK Productivity Tool for open that excel file in xml mode and see all the tags you need to change to customize your graph – Rodolpho Freire Nov 12 '14 at 16:49

2 Answers2

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
Community
  • 1
  • 1
Angel Doza
  • 1,096
  • 1
  • 18
  • 34
0

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

Community
  • 1
  • 1