1

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!

4

1 回答 1

10

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

您需要做的是修改 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);

然后你需要ToIntensity($Value)在类中添加你自己的函数:

function ToIntensity($Value)
    {

     switch($Value) {
       case 0:
       return "low";
       break;
       case 1:
       return "medium";
       break;
       case 2:
       return "strong";
       break;
     }
    }
于 2010-03-22T03:06:33.643 回答