JpGraph图例顺序

发布于 2024-12-08 13:11:13 字数 121 浏览 1 评论 0原文

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

I'm using an accumulated bar plot with JpGraph and want to change the order in which the items appear in the legend (I want to sort them alphanumerically). I've checked the documentation, but didn't find anything related: do I have any options for achieving this? (JpGraph seems to sort the legend on its own)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻许诺言 2024-12-15 13:11:13

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

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

$graph->legend->SetReverse();

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

Sadly, I dont believe there is directly, however:

By default the ordering of the texts in te legend will be the same as
the order the plots are added to the graph. It is also possible to
reverse this order in the legend with a call to the method
Legend::Reverse()

$graph->legend->SetReverse();

You could programatically sort your series as you wish before pushing them to the graph in your desired order to achieve what you're after...

东走西顾 2024-12-15 13:11:13

在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 语句!

In jpgraph-4.4.2/src/jpgraph_bar.php, in the Function Legend change the order of the for statement! It seems to reverse it intentionally. Not
sure why.

Here is the original code:

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

Here is the new code that works for me:

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

Only difference is changing the for statement!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文