我编写了一个代码,它以以下格式从mixpanel返回JSON 对象:
**{"legend_size": 1, "data": { "series": ["2013-09-25 14:00:00", "2013-09-25 15:00:00", "2013-09-25 16:00:00"], "values": { "Demoevent": {"2013-09-25 20:00:00": 0, "2013-09-25 12:00:00": 44, "2013-09-25 15:00:00": 1, "2013-09-25 01:00:00": 0 }}}}**
代码处理这个传递给HighCharts 方法的JSON 对象以动态生成图表。
这是原始格式的代码:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js" />
<script type="text/javascript" src="jquery.md5.js"></script></script>
<script type="text/javascript" src="mixpanelClient.js"></script></script>
<script type="text/javascript" src="underscore-min.js"></script></script>
<script type="text/javascript" src="md5.js"></script></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script>
$(document).ready(function() {
var eventToDisplay = "acall finished";
var apiKey = "BigSecret1";
var apiSecret = "BigSEcret2";
var mpEvent = {
'event': [eventToDisplay, ],
'type': 'general',
'unit': 'hour',
}
var mpClient = MixpanelClient(apiKey, apiSecret);
var requestUrl = mpClient.getRequestUrl(['events'], mpEvent);
console.log("The RequestUrl is:", requestUrl);
var JsonData=null;
var options = {
chart: {
renderTo: 'container',
type: 'column'
},
title:{
text: 'Total Calls Finished'
},
xAxis: {
type: 'datetime',
title: {
text: "Date"
},
},
yAxis: {
title:{
text: 'Count of Calls',
},
},
series:[]
};
$.ajax({
type:"GET",
url: requestUrl,
//The request url returns a JSON object.I have checked it on the console.Attached the screenshot too.
success: function(data) {
JsonData=data;
**options.series[0].data.values = JsonData.data.values["acall finished"];
var chart = new Highcharts.Chart(options);**
alert("Chart Created");
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status);
},
dataType: "jsonp"
});
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
现在这里是控制台的屏幕截图,它清楚地显示了我的控制台上的 JSON 对象。
问题是我得到一个空白图表。没有列,什么都没有。请帮助。我对 HighCharts 很陌生。
谢谢卡维什