- Code: Select all
{
"mydata": [
{
"y": 1,
"url": "http://www.highcharts.com"
},
{
"y": 2,
"url": "http://www.bbc.co.uk"
}
]
}
My code looks like this:
- Code: Select all
<script type='text/javascript'>
$(document).ready(function() {
var options = {
chart: {
renderTo: 'hgraphcontainer',
defaultSeriesType: 'column'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function() {
location.href = this.options.url;
}
}
}
}
},
series: []
};
var seriesOptions = {
name: 'Calls',
data: []
};
$.getJSON('json.txt', function(mydata) {
$.each(mydata.mydata, function(key, val) {
//alert (key + " " + val.y + ": " + val.url);
//alert (key + " " + parseInt(val.y));
seriesOptions.data.push(val);
});
});
alert("ok");
options.series.push(seriesOptions);
var chart = new Highcharts.Chart(options);
});
</script>
It works if I have the alert("ok") after getting the data but if I leave that out I get no chart. Can anyone explain why or suggest a better way to do this?
Thanks
Lee