问题描述
我正在使用PHPExcel,以便使用条形图导出Excel图表.
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:
但是,我想在图表顶部进行轴布局,并将Y轴反转为该图像:
But, I want to make the axis layout at the top of chart and reverse the Y-axis as this image:
我该怎么做?
推荐答案
研究代码后,我发现可能使轴反转:
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);
该轴是反向的,因此您设置为Y轴的选项将应用于X轴,而相反的轴.
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);
或
$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
);
这篇关于PHPExcel图表不反转垂直轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!