jQuery绘制图表json数据


jQuery Plot chart json data

我对jQuery绘图图有问题,它运行良好,但当我从php和json加载数据时,它不起作用,它什么也不显示。

这是我从php 得到的结果

[{"label":"Patrik","data":4},{"label":"Miroslav","data":28}]

和flot

            $.getJSON( "http://"+window.location.hostname+"/dashboard/getChartData", function( data ) {
            console.log(data);
            var options = {
                series: {
                    bars: {
                        show: true
                    }
                },
                bars: {
                    align: "center",
                    barWidth: 0.5
                },
                xaxis: {
                    ticks: data.title
                },
                legend: {
                    noColumns: 0,
                    labelBoxBorderColor: "#fff",
                    position: "nw"
                },
                grid: {
                    hoverable: true,
                    borderWidth: 1,
                    borderColor: "#cecece",
                    backgroundColor: { colors: ["#ffffff", "#EDF5FF"] }
                }
            };
            $.plot($("#chart_1_1"), [ data ], options);
        });

您接收的Json数据需要转换为数组格式[[key,value],[key,value]]的数组,然后才能将其提供给jqplot。当前您有一个对象数组