Ah now I see what you meant, clever code,
I am more on the php side thus I did test some php script to achive
different colored base bars based on trigger values and came up with
this example:
Let us load the data string which builds the bars chd URL parameter
into one array.
$data1 = array(10,50,60,80,40);
As we want some stacked bars where each bar has two sets of values,
create an array for each,
one for the lower and one for the upper the upper set.
$data2 = array(50,60,100,40,20);
Let us build an array for the base color and set a trigger value.
$color1 = array();
$trigger = 50;
Use the arrays to build the string parsed for the bar values:
foreach($data1 as $value)
Than checked each array value and based on a trigger e color values
can be calculated
if ($value < $trigger )
{
$color = "FF0000";
}
else
{
$color = "FFC000";
}
Than load the calculated value into the color array:
$color1[] = $color;
Though I would have liked XML style data parsing much better but let
us face the facts,
the API does not use XML we need to build some "," separated listing
of values as a string:
$valuestringA = $valuestringA.$value."," ;
Ups the last one will be a "," , The API does not expect this so we
need to get rid of it, delete the last sign of the string:
$valuesA = substr($valuestringA, 0, -1);
Now let us get the second data set same method as above:
foreach($data2 AS $value)
{
$valuestringB = $valuestringB.$value."," ;
}
$valuesB = substr($valuestringB, 0, -1);
Ok now let us put both together to form the chd string expected
$chd = $valuesA ."|".$valuesB ;
Ok last part let us build the color value URL param string and parse
it into the $chco variable:
foreach($color1 AS $colorstring)
{
$colorstringA = $colorstringA.$colorstring."|" ;
}
$chco = substr($colorstringA, 0, -1);
And now let us work the embedded code:
<img src="http://chart.apis.google.com/chart?
cht=bhs
&chs=200x125
&chd=t:<?php echo $chd ?>
&chco=<?php echo $chco ?>,FFC00059
&chbh=20"
alt="Horizontal bar chart with two data sets: and lower set 2 colored
based on min value">
<br>
Sure that can be build into a function but I just needed a proof of
concept.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en
-~----------~----~----~----~------~----~------~--~---