PHPExcel Chart not reversing the vertical axis

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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:

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

How can I do that?

回答1:

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 );


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!