JpGraph图例顺序

问题描述 投票:0回答:2

我正在使用 JpGraph 的累积条形图,并且想要更改项目在图例中出现的顺序(我想按字母数字顺序对它们进行排序)。我检查了文档,但没有找到任何相关内容:我有什么选择可以实现这一目标吗? (JpGraph似乎自己对图例进行排序)

php diagram legend jpgraph
2个回答
2
投票

可悲的是,我不相信直接存在:

默认情况下,图例中文本的顺序与 将图添加到图表中的顺序。也可以 通过调用该方法来颠倒图例中的顺序 图例::反向()

$graph->legend->SetReverse();

您可以按照您的意愿以编程方式对您的系列进行排序,然后按照您想要的顺序将它们推送到图表中以实现您想要的...


0
投票

在jpgraph-4.4.2/src/jpgraph_bar.php中,在Function Legend中更改for语句的顺序!看来是故意扭转的。不是 确定为什么。

原代码如下:

 function Legend($graph) {
    $n = count($this->plots);
    for( $i=$n-1; $i >= 0; --$i ) {                                                                                 
    $c = get_class($this->plots[$i]);
        if( !($this->plots[$i] instanceof BarPlot) ) {
            JpGraphError::RaiseL(2012,$c);
                                                                                          
        }
        $this->plots[$i]->DoLegend($graph);
    }
}

这是适合我的新代码:

  function Legend($graph) {
    $n = count($this->plots);
    //  for( $i=$n-1; $i >= 0; --$i ) {                                                                                 
    for( $i=0; $i< $n; ++$i ) {
    $c = get_class($this->plots[$i]);
        if( !($this->plots[$i] instanceof BarPlot) ) {
            JpGraphError::RaiseL(2012,$c);
                                                                                     
        }
        $this->plots[$i]->DoLegend($graph);
    }
}

唯一的区别是更改 for 语句!

© www.soinside.com 2019 - 2024. All rights reserved.