|
Very problem |
Posted by Gooffy on Oct-17-2010 20:17 |
|
Hi there,
anybody can help me please
I have one problem:
In example of Multi-Line Chart, if i want to create graph from query (database) such as
for($i=0;$i<count($_GET["chkconditional"]);$i++)
{
for($j=1;$j<=31;$j++)
{
$day=$j;
$sql = "SELECT SUM(size)FROM traffic_usage WHERE month(timestamp)= '$month' AND day(timestamp) = '$day' AND app_no = '$app_no'";
$result = mysql_query($sql) or die(mysql_error());
list($r)=mysql_fetch_row($result);
$data[$i][$j]=$r;
$labels[$j-1]=$j;//la = label
}
# Create an XYChart object of size 600 x 300 pixels, with a light blue (EEEEFF)
# background, black border, 1 pxiel 3D border effect and rounded corners
$c = new XYChart(600, 300, 0xeeeeff, 0x000000, 1);
$c->setRoundedFrame();
# Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white background.
# Turn on both horizontal and vertical grid lines with light grey color (0xcccccc)
$c->setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
# Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 9 pts
# Arial Bold font. Set the background and border color to Transparent.
$legendObj = $c->addLegend(50, 30, false, "arialbd.ttf", 9);
$legendObj->setBackground(Transparent);
# Add a title box to the chart using 15 pts Times Bold Italic font, on a light blue
# (CCCCFF) background with glass effect. white (0xffffff) on a dark red (0x800000)
# background, with a 1 pixel 3D border.
$textBoxObj = $c->addTitle("Application Server Throughput", "timesbi.ttf", 15);
$textBoxObj->setBackground(0xccccff, 0x000000, glassEffect());
# Add a title to the y axis
$c->yAxis->setTitle("Bandwidth (bytes)");
# Set the labels on the x axis.
$c->xAxis->setLabels($labels);
# Display 1 out of 3 labels on the x-axis.
$c->xAxis->setLabelStep(1);
# Add a title to the x axis
$c->xAxis->setTitle("This month");
# Add a line layer to the chart
$layer = $c->addLineLayer2();
# Add the three data sets to the line layer. For demo purpose, we use a dash line
# color for the last line
$layer->addDataSet($data[$i], 0xff0000, $temp);
# Set the default line width to 2 pixels
$layer->setLineWidth(2);
# Output the chart
header("Content-type: image/jpeg");
print($c->makeChart2(JPG));
}
but i can't crete multi-line chart but i can create one line chart
Regards
Gooffy |
Re: Very problem |
Posted by Peter Kwan on Oct-19-2010 04:21 |
|
Hi Gooffy,
For your case, your code currently creates a new chart for every iteration of the outer for loop, each time adding only one data series to the chart. As it is illegal accordng to the HTML/HTTP standard to output multiple chart images in the same HTTP connection, your code probably will not work.
If you want to create a multi-line chart, please create just one XYChart, and add all the data to the chart. please add your data to the same XYChart. It is like:
for($i=0;$i<count($_GET["chkconditional"]);$i++)
{
for($j=1;$j<=31;$j++)
{
$day=$j;
$sql = "SELECT SUM(size)FROM traffic_usage WHERE month(timestamp)= '$month' AND day(timestamp) = '$day' AND app_no = '$app_no'";
$result = mysql_query($sql) or die(mysql_error());
list($r)=mysql_fetch_row($result);
$data[$i][$j]=$r;
$labels[$j-1]=$j;//la = label
}
}
# Create an XYChart object of size 600 x 300 pixels, with a light blue (EEEEFF)
# background, black border, 1 pxiel 3D border effect and rounded corners
$c = new XYChart(600, 300, 0xeeeeff, 0x000000, 1);
$c->setRoundedFrame();
# Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white background.
# Turn on both horizontal and vertical grid lines with light grey color (0xcccccc)
$c->setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
# Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 9 pts
# Arial Bold font. Set the background and border color to Transparent.
$legendObj = $c->addLegend(50, 30, false, "arialbd.ttf", 9);
$legendObj->setBackground(Transparent);
# Add a title box to the chart using 15 pts Times Bold Italic font, on a light blue
# (CCCCFF) background with glass effect. white (0xffffff) on a dark red (0x800000)
# background, with a 1 pixel 3D border.
$textBoxObj = $c->addTitle("Application Server Throughput", "timesbi.ttf", 15);
$textBoxObj->setBackground(0xccccff, 0x000000, glassEffect());
# Add a title to the y axis
$c->yAxis->setTitle("Bandwidth (bytes)");
# Set the labels on the x axis.
$c->xAxis->setLabels($labels);
# Display 1 out of 3 labels on the x-axis.
$c->xAxis->setLabelStep(1);
# Add a title to the x axis
$c->xAxis->setTitle("This month");
# Add a line layer to the chart
$layer = $c->addLineLayer2();
# Add the three data sets to the line layer. For demo purpose, we use a dash line
# color for the last line
for ($i = 0; $i < count($_GET["chkconditional"]); ++$i)
$layer->addDataSet($data[$i], 0xff0000, $temp);
# Set the default line width to 2 pixels
$layer->setLineWidth(2);
# Output the chart
header("Content-type: image/jpeg");
print($c->makeChart2(JPG));
Hope this can help.
Regards
Peter Kwan |
|