这是我想用flot(jquery库)
绘制的数据其中action位于x轴上,计数位于y
上var data= [{"action":"QUERY INSURANCE","count":"9"},{"action":"QUERY POLICE DETAILS","count":"15"},{"action":"QUERY VEHICLE DETAILS","count":"3"},{"action":"CIVILIAN DETAILS","count":"1"},{"action":"LOGGING IN","count":"59"},{"action":"Report Occurrence","count":"1"},{"action":"QUERY CRIMINAL RECORDS","count":"2"},{"action":"QUERY VEHICLE OFFENCES","count":"2"},{"action":"QUERY DL VALIDITY","count":"5"},{"action":"REPORT OCCURRENCE","count":"23"}];
$.plot($("#plotrr"), [
{
data: data,
bars: { show: true }
}]);
如何在x轴上显示“动作”,在y轴上显示“计数”
答案 0 :(得分:8)
您需要做的是在flot选项中为ticks
指定xaxis
参数,并将每个操作设置为其中一个标记。所以你会做0 =查询保险,1 =查询警察详情等等:
$.plot($("#plotrr"), [
{
data: [[0,9],[1,15] ... ], //fill out the rest of your counts sequentially here
bars: { show: true }
}],
//flot options
{
xaxis: {
ticks: [[0,'Query Insurance'],[1,'Query Police Details'] ...] //fill out the rest here
}
});
另一个警告是,当它们应该是数字时,您的计数似乎是字符串 - 即count: "9"
错误,count: 9
是正确的。