tags:

views:

210

answers:

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!

+2  A: 

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;
     }
    }
Cetra
Too good answer. I feel guilty for such a easy to implement answer. Thank you very much! It worked like charm.
Sortea2
+1 - a great answer deserving of more votes. Too bad pChart has a low profile on SO!
Andrew Heath