Omit Curve for null values then continue plot it for real values with
Libchart
I use Libchart to draw curve for data in my database. My problem is:
Libchart plots (zero value) for my null data (Y axis values). I need
Libchart draw (X axis value) but not draw curve for (Y axis value) when Y
is null. In another words I need the curve to be omitted for null values,
and then continue plotting for real values. Below code which I used to
draw the curve:
<?php
$x1="Value 1";
$x2="Value 2";
$x3="Value 3";
$x4="Value 4";
$x5="Value 5";
$x6="Value 6";
$x7="Value 7";
$x8="Value 8";
$x9="Value 9";
$x10="Value 10";
$x11="Value 11";
$x12="Value 12";
$y1=45;
$y2=06;
$y3=82;
$y4=15;
$y5=45;
$y6=null;
$y7=null;
$y8=null;
$y9=null;
$y10=75;
$y11=16;
$y12=34;
include "libchart/classes/libchart.php";
$chart = new LineChart(1000, 400);
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point($x1,$y1));
$dataSet->addPoint(new Point($x2,$y2));
$dataSet->addPoint(new Point($x3,$y3));
$dataSet->addPoint(new Point($x4,$y4));
$dataSet->addPoint(new Point($x5,$y5));
$dataSet->addPoint(new Point($x6,$y6));
$dataSet->addPoint(new Point($x7,$y7));
$dataSet->addPoint(new Point($x8,$y8));
$dataSet->addPoint(new Point($x9,$y9));
$dataSet->addPoint(new Point($x10,$y10));
$dataSet->addPoint(new Point($x11,$y11));
$dataSet->addPoint(new Point($x12,$y12));
$chart->setDataSet($dataSet);
$chart->setTitle("Monthly usage for www.example.com");
$chart->render("generated/demo1.png");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
<center><img alt="my_curve" src="generated/demo1.png" style="border: 1px
solid gray;"/></center>
</body>
</html>
No comments:
Post a Comment