tags:

views:

452

answers:

2

Hi Guys,

I am using pChart PHP component for chart drawing. What is happening is that for some values it just hangs and doesn't draw the chart. Here is my code:

$DataSet = new pData;
$DataSet->AddPoint(array(111220, 180496, 103366, 110603, 107354, 100896, 103335, 101180, 102134, 102682, 99938, 96807, 95746, 100057, 95694, 97747, 95919, 94873, 98016, 95627, 98761, 98486, 103944, 106017, 114371, 164686, 104440, 104626, 107983, 119216, 112167, 108124),"YSerie");
$DataSet->AddSerie("YSerie");
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("AverageResponses","YSerie");

// Initialise the graph
$Test = new pChart(180, 80);
$Test->createColorGradientPalette(38, 89, 129, 83, 108, 126, 2);
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(0, 0, 180, 80);
$Test->drawGraphArea(0, 0, 0);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0,   0, 0, FALSE); 

$Test->drawFilledLineGraph($DataSet->GetData(),$DataSet->GetDataDescription(),50,TRUE);
$Test->Stroke();

For this values, chart isn't plotted, it just hangs. On the other hand, for this ones

array(32) { [0]=>  int(149871) [1]=>  int(176304) [2]=>  int(129938) [3]=>  int(145667) [4]=>  int(129792) [5]=>  int(128161) [6]=>  int(133420) [7]=>  int(137339) [8]=>  int(139754) [9]=>  int(103679) [10]=>  int(101300) [11]=>  int(113009) [12]=>  int(120305) [13]=>  int(113353) [14]=>  int(115820) [15]=>  int(118757) [16]=>  int(110967) [17]=>  int(112973) [18]=>  int(160397) [19]=>  int(291838) [20]=>  int(131905) [21]=>  int(130459) [22]=>  int(130835) [23]=>  int(125083) [24]=>  int(131659) [25]=>  int(133908) [26]=>  int(139401) [27]=>  int(139670) [28]=>  int(144980) [29]=>  int(147294) [30]=>  int(157745) [31]=>  int(163248) } 

get plotted correctly. Any ideas what could be the problem?

Thanks, Mladen

+1  A: 

There is a bug in the drawScale() function.

In this function you have the following part:

while(!$ScaleOk and $counter < 10)
{
 $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
 $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
 $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;

 if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}

 if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}

 if (!$ScaleOk)

  {

   if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }

   if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }

  }
}

You're graph isn't high enough, and then this algorithm keeps bouncing between 2 scales, one just too small, the other just too big.

You can fix it by making it higher:

$Test = new pChart(180, 80);
$Test->setGraphArea(0, 0, 180, 100);

Or by setting the scale yourself.

Jimmy Shelter
This makes sense :) Can you just tell me how to set the scale myself as resizing the graph is not the option?
Mladen
There's a function called setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5). Maybe you can use that one.
Jimmy Shelter
great, thx a lot
Mladen
A: 

Worked for me.

I put the follow command before drawScale:

$Test->setFixedScale(0, $max_value_from_your_data );
Simone