I'm using this script from Google to create a combo chart.
https://developers.google.com/chart/interactive/docs/gallery/combochart
Because of my situation, I'm using php to get the data from the database. Since the problem isn't about getting the data, for the code below I'm just hard coding $CT_Companies=4 to show the problem (in practice the number 4 comes from the database.
Here is the php function to create the configuration series needed to make the combo bar and line chart.
$CT_Companies=4;
function bar_series(){
global $CT_Companies;
$ser="";
for ($i = 0; $i <= $CT_Companies; $i++) {
if ($i==$CT_Companies ) {
$ser .= $i.":{type: 'line'}";
} else {
$ser .= $i.":{visibleInLegend: true}, ";
}
}
return $ser;
}
and here is the javascript I use to create the configuration series.
var options = {
series: {
<?php echo bar_series(); ?>
}
}
This does not work since while it does show the graph as expected, there is no line graph. Now, if I put $CT_Companies=4 inside the bar_series function it works fine and the line graph shows as expected. So it looks like the global isn't working. One more piece of information...if I echo bar_series() in the php section (not the javascript section) in both cases, the series is echoed and looks as expected. I very confused why this isn't working.