phpgraphstocksgchart

gchartphp addDataSet() max limit?


I'm trying to create a PHP script that graphs some historical stock data.

I have the data in an array and am trying to graph it with gchartphp using this code:

require_once("../gchart/gChart.php");
$lineChart = new gLineChart(1000, 200);
//********PROBLEM HERE**********
$lineChart->addDataSet($yearsData); 
//******************************
$lineChart->setLegend(array('Nice figures'));
$lineChart->setColors(array('ED237A'));
$lineChart->setVisibleAxes(array('x','y'));
$lineChart->setDataRange(0,1);
$lineChart->setLegendPosition('r');
// axisnr, from, to, step
$lineChart->addAxisRange(0,0,365);
$lineChart->addAxisRange(1,0,1);

$lineChart->setGridLines(floatval(1.9),10);
$lineChart->renderImage(true);

If I put something like this in addDataSet it works and the graph displays.

array(0.34234, 1, 10, .01, 20)

However, if I put an array with 365 values in addDataSet the graph does not render and the page shows a broken image symbol. The page shows no warnings or errors.

Any suggestions? Is there a limit to how many values you can graph?


Solution

  • AFAIK, 365 values should be fine for a POST. If you did a GET, then there would be more of a chance of the size being too large.

    The probable issue is:
    1) You are not outputting the image.

    $lineChart->renderImage(true); by itself will not produce an image. You need to set the png data generated by your script as the src for an tag. So if the above script is 'graph.php', then you would display it in a separate file like:

    <img src='graph.php' />

    2) You are echoing data to the screen while generating the image.

    If you take a look at the renderImage function code inside of gChart.php,
    the first line is header('Content-type: image/png');

    So outputting even one character to the screen before this call, such as debug output (in graph.php) will break your image. For example, the following will produce a broken image.

    echo "x";
    $chart->renderImage( true );