Location: PHPKode > scripts > Line Chart Script > hlinechart/linechart.php
<?php
include 'config.php';
$link=mysql_connect("$hostname","$username","$password")or 
die('Could not connect: ' . mysql_error());
mysql_select_db("$dbname",$link);
include 'create.php';
$itemval=array();
$itemnam=array();
$sql="SELECT xvalue,yvalue FROM $tablename"; //field name x axis value and yaxis value
$result = mysql_query($sql);
$i=0;
while($inf = mysql_fetch_array($result)) 
  {
  $itemval[$i]=$inf[1];
  $itemnam[$i]=$inf[0];
$i++;
}
include 'linecolor.php';
include("pChart/pData.class");
include("pChart/pChart.class");
  
 // Dataset definition
 $DataSet = new pData;
 $DataSet->AddPoint($itemval,"Serie1");
 //$DataSet->AddPoint(array(40,50,60,80,70,60),"Serie2");
 $DataSet->AddPoint($itemnam,"Serie3");
 $DataSet->AddSerie("Serie1");
 //$DataSet->AddSerie("Serie2");
 $DataSet->SetAbsciseLabelSerie("Serie3");
 //$DataSet->SetSerieName("Company A","Serie1");
 //$DataSet->SetSerieName("Company B","Serie2");
 $DataSet->SetYAxisName($yname);
$DataSet->SetXAxisName($xname);
 //$DataSet->SetYAxisUnit("k");
 //$DataSet->SetSerieSymbol("Serie1","Sample/Point_Asterisk.gif");
 

 // Initialise the graph   
 $Test = new pChart($img_width,$img_height);
 $Test->setFontProperties("Fonts/tahoma.ttf",9);
 $Test->setGraphArea(65,30,$img_width-50,$img_height-50);
 $Test->drawFilledRoundedRectangle(7,7,$img_width-7,$img_height-7,5,$bagcolr,$bagcolg,$bagcolb);
 $Test->drawRoundedRectangle(5,5,$img_width-5,$img_height-5,5,$bagcolr,$bagcolg,$bagcolb);
 //$Test->drawGraphArea(255,255,255,TRUE);
 $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,$txtcolr,$txtcolg,$txtcolb,TRUE,0,5,TRUE);
 //$Test->drawGrid(4,TRUE,230,230,230,50);
  
 // Draw the title
 $Test->setFontProperties("Fonts/tahoma.ttf",10);   
 $Test->drawTitle($img_width/2,20,$graphtitle,$titcolr,$titcolg,$titcolb); 
 // Draw the line graph
 $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"",$linecolr,$linecolg,$linecolb);
 $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,$linecolr,$linecolg,$linecolb);
  
 // Draw the legend
 // Render the chart
 $Test->Render("linechart.jpg"); 
echo "<div style='border:1px solid #d8d8d8;width:$img_width'><img src='linechart.jpg'></div>";
?>
<div style="font-size: 10px;color: #dadada;" id="dumdiv">
<a href="http://www.hscripts.com" id="dum" style=" padding-left:200px; text-decoration:none;color: #dadada;">&copy;h</a></div>
Return current item: Line Chart Script