BigEgg
BigEgg

Reputation: 101

PHPExcel Chart not reversing the vertical axis

I'm working with PHPExcel in order to export Excel chart with Bar Chart.

I can export the chart with the default layout as this image:

enter image description here

But, I want to make the axis layout at the top of chart and reverse the Y-axis as this image:

enter image description here

How can I do that?

Upvotes: 4

Views: 3125

Answers (1)

Pavel Petrov
Pavel Petrov

Reputation: 867

After researching the code I found that it is possible to reverse the axis:

$yAxis = new \PHPExcel_Chart_Axis();
$yAxis->setsetAxisOptionsProperties(
    \PHPExcel_Chart_Axis::AXIS_LABELS_NEXT_TO, 
    null, 
    null, 
    \PHPExcel_Properties::ORIENTATION_REVERSED
);

$chart = new \PHPExcel_Chart(
    "Chart1", 
    $titile, 
    $legend, 
    $plotArea, 
    true, 
    '0', 
    null, 
    null, 
    null, //xAxis parameter if you want to reverse the x axis
    $yAxis
);

NOTE: If you set the series direction to columns instead of bars

$series = new \PHPExcel_Chart_DataSeries(....);
$series->setPlotDirection(\PHPExcel_Chart_DataSeries::DIRECTION_COL);

the axis are reversed, so what you set as options for the Y-axis will be applied to the X-axis and the opposite.

However reversing the axis cannot be achieved by other methods expected to work:

$chart->getChartAxisY()->setAxisOrientation(\PHPExcel_Properties::ORIENTATION_REVERSED);

or

$yAxis = new \PHPExcel_Chart_Axis();
$yAxis->setAxisOrientation(\PHPExcel_Properties::ORIENTATION_REVERSED);

$chart = new \PHPExcel_Chart(
    "Chart1", 
    $titile, 
    $legend, 
    $plotArea, 
    true, 
    '0', 
    null, 
    null, 
    null, //xAxis parameter if you want to reverse the x axis
    $yAxis
);

Upvotes: 1

Related Questions