JQuery 绘图在 $.getJSON 中不起作用

发布于 2024-08-11 18:36:40 字数 781 浏览 2 评论 0原文

javascript中的代码是

$(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);
  });});

http://localhost:8085/WebApplication1/metricsJson.jsp?instanceId=3457 返回

{"data":[[[1258216500000,4.91],[1258212240000,4.39],[1258216920000,4.46],[1258211640000,4.39],[1258210980000,4.82] ]]}

谢谢

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":[[[1258216500000,4.91],[1258212240000,4.39],[1258216920000,4.46],[1258211640000,4.39],[1258210980000,4.82] ]]}

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-08-18 18:36:40

我通常会在发帖前进行测试,但这里我会盲目发帖。

我相信要检查的一件事是如何将数据传递给flot。我认为您对浮点绘图仪的调用应该如下所示(考虑到变量的命名方式):

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

这是因为 JSON 的工作原理。

其次,我认为 flot 需要一个 2d 数组,而不是 3d 数组。您的 JSON 对象由另一个数组中的 2 个元素数组组成。如果可以的话,让你的服务器只返回一个二维数组。否则你可以尝试:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文