0

Using pChart to draw plot graphs:

$Data = new pData();
$Data->AddPoints(array(1,2,10), 'x');
$Data->AddPoints(array(6,8,3), 'y');
$Data->setAbscissa('x');

$Chart = new pImage($w, $h, $Data);
$Chart->setGraphArea(100, 0, $w-1, $h-50);  
$Chart->drawScale(array('Mode' => SCALE_MODE_FLOATING));
$Chart->drawPlotChart();    
$Chart->Stroke();

On the plot, the distance along the X axis from 1 to 2 is the same as the distance from 2 to 10. How do I make pChart interpret abscissa values as the numbers they are?

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281

2 Answers2

1

I had a look into pChart code, and I'm almost sure that this is their only way to render data: X-axis ticks are spread evenly, number of ticks equals to number of data points in series.

But you still can get what you want by defining some points as missing. In case of your specific example "fixed" code would look like this (the rest is unchanged):

$Data->AddPoints(array(1,2,VOID,VOID,VOID,VOID,VOID,VOID,VOID,10), 'x');
$Data->AddPoints(array(6,8,VOID,VOID,VOID,VOID,VOID,VOID,VOID,3), 'y');

VOID is a constant defined somewhere within pData.class.php, so, you already have it available.

And here is how end result looks like: https://i.stack.imgur.com/j8Owr.jpg ($w = 500; $h = 400;)

alx
  • 2,314
  • 2
  • 18
  • 22
0

A scatter plot is what I'm looking for. This draws the right X-Y plot:

$Data = new pData();
$Data->AddPoints(array(1,2,10), 'x');
$Data->AddPoints(array(6,8,3), 'y');
$Data->setAxisXY(0,AXIS_X);
$Data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
$Data->setAxisXY(1,AXIS_Y);
$Data->setSerieOnAxis('y', 1);
$Data->SetScatterSerie('x', 'y');

$Chart = new pImage($w, $h, $Data);
$Chart->setGraphArea(100,0,$w-1,$h-50);  

$Scatter = new pScatter($Chart, $Data);
$Scatter->drawScatterScale();
$Scatter->drawScatterPlotChart(array());
$Chart->Stroke();
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281