使用 PChart 标记 Y 轴

发布于 2024-08-25 22:39:09 字数 382 浏览 10 评论 0原文

我正在使用 PChart for PHP 来绘制图表,它运行得很好。

我绘制了一个强度图(2 = 强,1 = 中,0 = 低),我想知道是否可以在 Y 轴上显示数据的描述(强,中、低)而不是不适当的数字(2,1,0)。

(我搜索了很多没有成功,理论上只能根据 http://pchart.sourceforge.net/documentation.php?topic=faq.xlabels。)

谢谢!

I am using PChart for PHP to draw graphs, it is working pretty well.

I have drawn a graph with intensities (2 = strong, 1 = medium, 0 = low) and I would like to know if is possible to show on the Y axis the description of the data (strong,medium,low) instead of the inappropriate numbers (2,1,0).

(I have search a lot without success, theoretically you can only set the X labels according to http://pchart.sourceforge.net/documentation.php?topic=faq.xlabels.)

Thanks!

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

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

发布评论

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

评论(1

风筝在阴天搁浅。 2024-09-01 22:39:09

有一种分配 Y 格式的方法。目前有 5 个:数字、时间、日期、公制和货币。您可以使用函数 SetYAxisFormat($Format) 在 pData 类中进行设置。

要实现您想要的效果,您需要修改 pChart.class 文件并包含您自己的格式化程序函数。

pChart.class 文件的不同位置,有以下代码部分:

   if ( $DataDescription["Format"]["Y"] == "number" )

    $Value = $Value.$DataDescription["Unit"]["Y"];

   if ( $DataDescription["Format"]["Y"] == "time" )

    $Value = $this->ToTime($Value);        

   if ( $DataDescription["Format"]["Y"] == "date" )

    $Value = $this->ToDate($Value);        

   if ( $DataDescription["Format"]["Y"] == "metric" )

    $Value = $this->ToMetric($Value);        

   if ( $DataDescription["Format"]["Y"] == "currency" )

    $Value = $this->ToCurrency($Value);   

要添加您自己的强度函数,在此位之后您需要添加:

   if ( $DataDescription["Format"]["Y"] == "intensity" )
    $Value = $this->ToIntensity($Value);

然后您需要添加您自己的 <类内的 code>ToIntensity($Value) 函数:

function ToIntensity($Value)
    {

     switch($Value) {
       case 0:
       return "low";
       break;
       case 1:
       return "medium";
       break;
       case 2:
       return "strong";
       break;
     }
    }

There is a way of assigning Y formats. Currently there are 5: Number, Time, Date, Metric and Currency. You set this in the pData class by using the function SetYAxisFormat($Format)

What you would have to do to acheive what you want is to modify the pChart.class file and include your own formatter function.

In various places in the pChart.class file, there is the following section of code:

   if ( $DataDescription["Format"]["Y"] == "number" )

    $Value = $Value.$DataDescription["Unit"]["Y"];

   if ( $DataDescription["Format"]["Y"] == "time" )

    $Value = $this->ToTime($Value);        

   if ( $DataDescription["Format"]["Y"] == "date" )

    $Value = $this->ToDate($Value);        

   if ( $DataDescription["Format"]["Y"] == "metric" )

    $Value = $this->ToMetric($Value);        

   if ( $DataDescription["Format"]["Y"] == "currency" )

    $Value = $this->ToCurrency($Value);   

To add your own intensity function, after this bit you would need to add:

   if ( $DataDescription["Format"]["Y"] == "intensity" )
    $Value = $this->ToIntensity($Value);

Then you would need to add your own ToIntensity($Value) function inside the class:

function ToIntensity($Value)
    {

     switch($Value) {
       case 0:
       return "low";
       break;
       case 1:
       return "medium";
       break;
       case 2:
       return "strong";
       break;
     }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文