【问题标题】:How to bring JPGraph second Y-axis data in front (AddY2)?如何将JPGraph第二个Y轴数据放在前面(AddY2)?
【发布时间】:2012-05-12 05:33:43
【问题描述】:

我有这个 JPGraph(有正确的数据):

// Create the graph. These two calls are always required
$graph = new Graph(640,350,"auto");
$graph->SetScale("textlin");
$graph->SetY2Scale("lin",0,100);

// Create the bar graph
$bplot1 = new BarPlot($datay);
$bplot1->SetFillGradient("darkolivegreen1","darkolivegreen4",GRAD_VERT);
$bplot1->SetWeight(0);
$graph->Add($bplot1);

// Create the line graph
$lplot = new LinePlot($datay2);
$lplot->SetBarCenter();
$lplot->SetStepStyle();
$graph->AddY2($lplot);

// Display the graph
$graph->Stroke();

这很好用(至少它显示了正确的数据)但我的问题是 Y2 数据在栏后面。我想要 Y2 数据在前面,这样数据就可以以不透明的方式显示,我可以看到它是多少百分比。

我已经尝试重新排列代码,以便 AddY2 排在第一位或最后,甚至将它混合,但仍然相同 - 总是在栏杆后面。

有人对此有任何见解吗?

如果这不可行,那么还有什么替代方案 - 任何其他与 JPGraph 一样出色的免费图形工具(我使用 CentOS 和 PHP)?

【问题讨论】:

    标签: php graph jpgraph


    【解决方案1】:

    如果我了解您想要实现的目标...尝试翻转 Y 刻度。

    $graph->Add($bplot1);$graph->AddY2($bplot1);

    $graph->AddY2($lplot); 变为 $graph->Add($lplot);

    编辑:

    我误解了...添加$graph->SetY2OrderBack(false); 会将Y2 放在Y1 的前景上。 来源: docs/classref/Graph.html#_GRAPH_SETY2ORDERBACK

    【讨论】:

    • 不,这不是一个选项,因为 $bplot1 图是主图。切换图表会使读者感到困惑,因为最重要的图表始终位于左侧 Y 轴上。
    • $graph->SetY2OrderBack(false);
    • 太棒了——“$graph->SetY2OrderBack(false);”修好了它,Y2现在就在前面。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 2014-06-08
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多