开发者

JQuery flot plot is not working in $.getJSON

开发者 https://www.devze.com 2022-12-11 05:34 出处:网络
The code in javascript is $(document).ready(function () {var options = { series: { points: { show: true }, shadowSize: 0 },

The code in javascript is

$(document).ready(function () {var options = {
    series: { points: { show: true }, shadowSize: 0 },
    xaxis: { mode: "time" },
    yaxis: {  min:0, max: 100 },
    pan: { interactive: true }};
    $.getJSON("http://localhost:8085/WebApplication1/metricsJson.jsp?instanceId=3457",
        function(data){
        alert(data);
        var plot = $.plot($("#placeholder"), data, options);
  });});

and http://localhost:8085/WebApplication1/metricsJson.jsp?instanceId=3457 returns

{"data":[[[12582165开发者_如何学JAVA00000,4.91],[1258212240000,4.39],[1258216920000,4.46],[1258211640000,4.39],[1258210980000,4.82] ]]}

thank you


I normally test before I post, but I will post blindly here.

I believe one thing to check is how you pass the data to flot. I think your call to the flot plotter should look like this (given how you have your variables named):

$.plot($("#placeholder"), data.data, options);

That's because of how JSON works.

Second, I think flot expects a 2d array, not a 3d one. Your JSON object consists of an array of 2 element arrays within another array. If you can, have your server only return a 2-d array. Otherwise you could try:

$.plot($("#placeholder"), data.data[0], options);
0

精彩评论

暂无评论...
验证码 换一张
取 消