Hi all
I'm dynamincally creating a table from a database to display number of orders received over time.
I wanted to use the Google Chart API to also display a nice chart at the same time.
I've got the code for creating this but I'm having one problem - the code requires an array and my data is in a string.
for some reason this isn't working and I'm assuming it's because of how PHP stores strings.
I've echo'd the strings to display the data and it's correct. I've even used copy and paste to put this into the url and it works fine.
Here's the code:
// Here's an array containing some data to plot
$string1 contains 1,2,1?
$test_data=array($string1);
// Here's where we call the chart, and return the encoded chart data
echo "<img src= vs Time")."&chf=c,lg,0,deb1b9,1,ffffff,0&cht=lc&chs=650x325&chd=".chart_data($test_data).">";
// And here's the function
function chart_data($values) {
// Port of JavaScript from //
// First, find the maximum value from the values given
$maxValue = max($values);
// A list of encoding characters to help later, as per Google's example
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
// Return the chart data - and let the Y axis to show the maximum value
return $chartData."&chxt=x,y&chxl=0:|".$string3."|1:|0|".$maxValue;
}
?>
Thanks
Kev
I'm dynamincally creating a table from a database to display number of orders received over time.
I wanted to use the Google Chart API to also display a nice chart at the same time.
I've got the code for creating this but I'm having one problem - the code requires an array and my data is in a string.
for some reason this isn't working and I'm assuming it's because of how PHP stores strings.
I've echo'd the strings to display the data and it's correct. I've even used copy and paste to put this into the url and it works fine.
Here's the code:
// Here's an array containing some data to plot
$string1 contains 1,2,1?
$test_data=array($string1);
// Here's where we call the chart, and return the encoded chart data
echo "<img src= vs Time")."&chf=c,lg,0,deb1b9,1,ffffff,0&cht=lc&chs=650x325&chd=".chart_data($test_data).">";
// And here's the function
function chart_data($values) {
// Port of JavaScript from //
// First, find the maximum value from the values given
$maxValue = max($values);
// A list of encoding characters to help later, as per Google's example
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
// Return the chart data - and let the Y axis to show the maximum value
return $chartData."&chxt=x,y&chxl=0:|".$string3."|1:|0|".$maxValue;
}
?>
Thanks
Kev