87,990
社区成员
发帖
与我相关
我的任务
分享
<div id="container" style="width:300px;height:300px"></div>
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
xAxis: {
labels: {
formatter: function() {
return dateFormat(this.value); //
}
}
},
series: [{
name: '重庆',
data: [
[Data.UTC(2014,1,1),1526],//Data.UTC()的返回值是number类型的,这个很重要
[Data.UTC(2014,2,1),4259],
[Data.UTC(2014,3,1),2542],
[Data.UTC(2014,4,1),1523],
[Data.UTC(2014,5,1),5234],
[Data.UTC(2014,6,1),4235],
[Data.UTC(2014,7,1),3524],
[Data.UTC(2014,8,1),2541],
]
}],
});
});
function dateFormat(time){
var now = new Date();
now.setTime(time);
return now.getFullYear()+"年"+(now.getMonth()+1)+"月"+(now.getDate());
}
也就是把X轴的值放入到series的data中去,但是x轴的值必须是number类型才可以,虽然有时候并不分得并理想,比如下面的例子:
<div id="container" style="width:300px;height:300px"></div>
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
xAxis: {
labels: {
formatter: function() {
return this.value+"个人"; //
}
}
},
series: [{
name: '第三组',
data: [
[1,1326],
[2,2259],
[3,3542],
[4,4523],
[5,5234],
[6,6235],
[7,8524],
[8,9541],
]
}],
});
});
