2

I'm not that good in PHP, what might be wrong with my code? Pls! Help. Here's my code in showing the graph:

function show_graph($input) {

$dataArray1 = array();
$dataArray2 = array();

//get data from database
$sql = sprintf("SELECT target_date, high, low FROM metal_price WHERE metal_kind ='%s' and metal_cd ='%s' and target_date BETWEEN '%s' and '%s' order by target_date", 
                $input["kind"], $input["cd"], 
                $input["date_from_y"]."/".$input["date_from_m"]."/".$input["date_from_d"], 
                $input["date_to_y"]."/".$input["date_to_m"]."/".$input["date_to_d"]);

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
    while ($row = mysql_fetch_assoc($result)) {
        $target_date=$row["target_date"];
        $high=$row["high"];
        $low=$row["low"];

        //add to data array
        $dataArray1[$target_date]=$high;
        $dataArray2[$target_date]=$low;
    }
}

$graph->addData($dataArray1);
$graph->addData($dataArray2);
$graph->setTitle('Metal Price Chart');
$graph->setBars(false);
$graph->setLine(true);
$graph->setLineColor('blue', 'green');
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->setDataValues(true);
$graph->setDataValueColor('maroon');
$graph->setLegend(true);
$graph->setTitleLocation('center');
$graph->setTitleColor('blue');
$graph->setLegendOutlineColor('white');
$graph->setLegendTitle('High', 'Low');
$graph->setGoalLineColor('blue', 'green');
$graph->setXValuesHorizontal(true);
$graph->createGraph();

}

I'm receiving this error every time i run my code: the image"http://localhost/chart/graph.php" cannot be displayed because it contains errors

hakaray
  • 21
  • 1

1 Answers1

0

Dont forget write include('phpgraphlib.php'); $graph = new PHPGraphLib(500,350); before $dataArray1 = array(); $dataArray2 = array();

kayla
  • 156
  • 1
  • 12