我正在制作一个重量图表。我通过JSON获取图表的数据,但问题是我没有xAxis的数据,只有日期。下面是数据的一个例子,我得到:通过json获得highcharts如何获得xAxis?
[
{"Date":"2011-03-02","y":"180"},
{"Date":"2011-03-03","y":"250"},
{"Date":"2011-03-09","y":"185"},
{"Date":"2011-03-03","y":"300"}
]
这里是我得到的数据,并呈现图表:
<script type="text/javascript">
var chart;
function requestData() {
$.getJSON('<?php echo Dispatcher::baseUrl();?>/logs/feed_data',
function (data) {
var series = chart.series[0];
series.setData(data);
}
);
}
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'contain',
defaultSeriesType: 'line',
marginRight: 130,
marginBottom: 25,
events: { load: requestData }
},
title: {
text: 'Your Weight History',
x: -20 //center
},
subtitle: {
text: 'Source: Fitness',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: '-weight -Pounds '
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y +' -Pounds';
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'Data1',
data: []
}]
});
});
</script>
是否有你展示的任何示例 – Muhaimin 2012-03-30 03:45:25
你的json应该是一个数组。据我所知,有一个特定的时间和日期格式。在某个日期时间之后应该以毫秒为单位。所以我建议让你的json格式适合高层建筑。 – SPandya 2013-12-17 06:34:43