0

这是我想用 flot 绘制的数据(jquery 库)

其中动作在 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 轴上显示“计数”

4

1 回答 1

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是正确的。

于 2012-07-03T15:42:02.703 回答