开发者

Labeling Y axis with PChart

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 开发者_C百科a lot without success, theoretically you can only set the X labels according to http://pchart.sourceforge.net/documentation.php?topic=faq.xlabels.)

Thanks!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜