<?php
include('./phplot.php');
$graph =& new PHPlot();

$example_data = array(
     array('a',3),
     array('b',5),
     array('c',7),
     array('d',8),
     array('e',2),
     array('f',6),
     array('g',7)
);
$graph->SetDataValues($example_data);
$graph->DrawGraph();
?>

When ever I run this program I get an error !
The image "http://localhost/test.php" cannot be displayed because it contains errors.

I also have GD library enabled!
What is the error ?
Please help!

try doing a var_dump.. that should give you something in return. Actually, I created a demo of this type of script as shown Click Here.

What I did was disassembled the class, because it is creating so much trouble. I don't think it is worth the hassle. So, class have to go.

try doing the arrays like this

 $data = array(
 array('', 1800,   5), array('', 1810,   7), array('', 1820,  10)

 );

Brief explanation on how the arrays related to plotting..

for example the above array represents the following 1800 is the x-axis 5 is the y-axis values, followed by the next dot or line continuation of the 1800 x-axis and the y-axis which 1820 and 10.

so by looking at your codes above you must add '' if it is a line graph, If it is a bar graph.. you can do like this

$data = array(
 array('x-axis value 1', 1),    array('x-axis value 2', 2),    array('x-axis value 3', 3)

 )

Again the second array above, demonstrate the proper convention of php plot.. x-axis, y-axis value. AND every thing in the array should be in ascending order.. like

(x = 1, y = 1), (x = 2, y =2),,, and so forth..

Before modifying your codes above, try this first by changing your codes below..

 $graph->SetDataValues($example_data);
 $graph->DrawGraph();

to this

 $graph->SetDataValues($example_data);
 $plot->SetDataType('text-data');
 $graph->DrawGraph();

try it, that should work.. here is the demo. of the same plot class using the same convention I described above..

Here is the demo of your array, using my recommended fix above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.