I have a php file and I connect it to the MySQL and fetch some values. I want to use these values in a .tpl file for showing graphs for which I am using Highcharts. I somehow am not being able to pass php values to the graph which is javascript. Please have a look at the code and tell me where am I going wrong.
My php code is:
$sqlStr = "select * from users where user_id=".$_SESSION['user_id'];
$sqlQuery = mysql_query($sqlStr) or die(mysql_error()."<hr>".$sqlStr);
if ( mysql_num_rows($sqlQuery) ) {
$rowMyReport = mysql_fetch_assoc($sqlQuery);
$smarty->assign("value1",$rowMyReport['value1']);
$smarty->assign("value2",$rowMyReport['value2']);
$smarty->assign("value3",$rowMyReport['value3']);
$smarty->assign("value4",$rowMyReport['value4']);
}
Now I want to use these values for Highcharts to have a graph on my website. So I tried this:
$(function () {
$('#graph').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,//null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Some-name',
data: [
['title1', <?php echo $value1; ?>],
['title2', <?php echo $value2; ?>],
['title3', <?php echo $value3; ?>],
['title4', <?php echo $value4; ?>]
]
}]
});
});
I call this graph in the .tpl file as such:
<div id="graph" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
By giving hard-coded values the graph gets displayed, but when I use dynamic values(php values) graph does not displayed. Any help would be appreciated...