PHP pchart 2.0 与每个条形对齐的附加标签

发布于 2024-11-29 19:20:02 字数 405 浏览 0 评论 0原文

您好,我有一个 pChart 2 条形图,其中包含可变数量的条形图以及每个条形图的实际值,我希望在每个条形图的右侧显示 2 个附加值。请考虑下图,其中矩形中的值是我需要添加到图表中的数字示例。

在此处输入图像描述

显然我想让它们看起来比这更整洁,但目前我只是想知道

什么在 pChart 中执行此操作的正确方法是吗?
是否有内置的方法来执行这种装饰? 如果不是,我应该如何最好地将我的附加输出与图表中的每个条形对齐,考虑到这些条形的像素大小和数据大小是可变的(即,必须针对单个场景进行计算而不是近似)。

为了清楚起见,额外的数字只是与前几年相同的分数,并且将用颜色边框或类似的装饰并包含在图例中。

谢谢。

Hi I have a pChart 2 bar chart which contains a variable number of bars and as well as the actual value for each bar I wish to display 2 additional values to the right hand side of each bar. Please consider the image below where the values in the rectangle are an example of the figures I need to add to the chart.

enter image description here

Obviously I want to make them look a bit neater than this but really at the moment I am just wondering

What would be the correct way to do this in pChart?
Is there a built in way to perform this kind of decoration?
If not, how should I best align my additional output with each bar in the chart, considering that these bars are variable in pixel size and data size (i.e. this has to be calculated not approximated for a single scenario).

Just for clarity the extra figures are simply the same scores from previous years and would be decorated in a colour border or similar and included in a legend.

Thanks.

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

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

发布评论

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

评论(1

风尘浪孓 2024-12-06 19:20:02

在文件 pDraw.class.php 的 drawBarChart() 方法中,该方法的末尾有以下条件:

if ($DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth)){
...
else{

else 块的末尾是 $this->drawText() 方法,该方法输出上的值小节的末尾,并且将为该系列中的每个小节调用。此时,您还可以使用以下内容将附加值写入图表的末尾(在本例中为右边距):

$itemGap = 45;  //the space between items
$items = array(1,2,3); //the value to draw


    $colStart = $this->GraphAreaX2 + $itemGap;

    foreach($itemGap as $item)
    {
         $this->drawText($colStart, $Y + $YOffset + $YSize / 2, $item, array("R" => $DisplayR, "G" => $DisplayG, "B" => $DisplayB, "Align" => $Align, "FontSize"  => $DisplaySize));
         $colStart += $itemGap;
    }

我希望这对某人有帮助。

In the drawBarChart() method of the file pDraw.class.php there is the following conditional at the end of that method:

if ($DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth)){
...
else{

At the end of that else block is a $this->drawText() method, this outputs the value on the end of the bar and will be called for each bar in the series. You can also at this point write additional values to the end of the chart (in this case the right margin) using the following:

$itemGap = 45;  //the space between items
$items = array(1,2,3); //the value to draw


    $colStart = $this->GraphAreaX2 + $itemGap;

    foreach($itemGap as $item)
    {
         $this->drawText($colStart, $Y + $YOffset + $YSize / 2, $item, array("R" => $DisplayR, "G" => $DisplayG, "B" => $DisplayB, "Align" => $Align, "FontSize"  => $DisplaySize));
         $colStart += $itemGap;
    }

I hope that is helpful to someone.

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