简体   繁体   English

当我尝试使用以下代码反转轴时,我没有获得反向

[英]When i Try to reverse the Axis with the following code i do not obtain the reverse orientation

When I try to reverse the axis with the following code I do not obtain the reverse orientation当我尝试使用以下代码反转轴时,我没有获得反向

$chart1->getChartAxisX()->setAxisOrientation(Axis::ORIENTATION_REVERSED);

How to change the coordinate axis from small to large?如何让坐标轴由小变大?

图一

图2

My guess is that you want the data sources to appear in the table in the same order as the bar chart, and your graph is a horizontal bar, so your code is fine, and it does invert the X-axis.我的猜测是您希望数据源以与条形图相同的顺序出现在表中,并且您的图形是水平条,因此您的代码很好,并且确实反转了 X 轴。 But why doesn't it work, and so I looked at the source code.但是为什么不行,所以我查看了源代码。 The code for getChartAxisX() in your method looks like this您方法中getChartAxisX()的代码如下所示

    public function getChartAxisX()
    {
        if ($this->xAxis !== null) {
            return $this->xAxis;
        }

        return new Axis();
    }

As you can see, when the member variable xAxis does not exist, this method creates a new object and returns it.可以看到,当成员变量xAxis不存在时,该方法会创建一个新对象并返回。 But this new object is not set into the $chart object, so your set method does not work on the $chart object.但是这个新对象没有设置到 $chart 对象中,所以你的 set 方法对 $chart 对象不起作用。

However, I have found that Chart does not have a setXAxis() method in PhpSpreadsheet, so if you want it to work, you should set the Axis object in when you create the $chart object.但是,我发现 Chart 在 PhpSpreadsheet 中没有 setXAxis() 方法,所以如果你想让它工作,你应该在创建 $chart 对象时设置 Axis 对象。

$axisX = new Axis();
$axisX->setAxisOrientation(Axis::ORIENTATION_REVERSED);
$chart = new Chart(
    "chart", // name
    $title, // title
    $legend, // legend
    $plotArea, // plotArea
    true, // plotVisibleOnly
    DataSeries::EMPTY_AS_GAP, // displayBlanksAs null,
    $xAxisLabel, // xAxisLabel - Owen added null xAxisLabel
    $yAxisLabel, // yAxisLabel
    $axisX //xAxis
);

Now it should do what you want.现在它应该做你想做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM