【发布时间】:2020-06-20 21:30:46
【问题描述】:
我有一个从中获取的数组
<div style='hidden' id=dataHours data-hours='{"08":3,"10":3,"11":1,"12":1,"14":2,"16":2,"18":1}'>
转成json数组。
我想使用 jqplot 创建一个矩阵,其中 x 轴为小时,y 轴为事件数。
我目前正在尝试此代码:
var json_data = $('#dataHours').data('hours');
var dateHoursArray = $.map(json_data, function(value, index) {
return [[index,value]];
});
console.log(dateHoursArray);
$.jqplot('maindiv', dateHoursArray, {
legend: {
show:true,
location : 'ne'
},
title: 'Tickets created per hour',
animate: true,
animateReplot: true,
axes: {
xaxis: {
label:'Hours',
autoscale: true,
min:0,
max:23,
rendererOptions: {
tickRenderer:$.jqplot.CanvasAxisTickRenderer
},
tickOptions: {
formatString:'%.0f'
}
},
yaxis: {
label:'Tickets',
autoscale: true
}
},
highlighter: {
sizeAdjust: 7.5
},
cursor: {
show: false
},
grid: {
gridLineColor: '#cccccc',
background: '#fff',
borderColor: '#000',
borderWidth: 2.0,
shadow: false,
}
});
但它并没有像我期望的那样工作。
有人吗?
【问题讨论】:
标签: javascript jquery jqplot