JQuery 绘图在 $.getJSON 中不起作用
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常会在发帖前进行测试,但这里我会盲目发帖。
我相信要检查的一件事是如何将数据传递给flot。我认为您对浮点绘图仪的调用应该如下所示(考虑到变量的命名方式):
这是因为 JSON 的工作原理。
其次,我认为 flot 需要一个 2d 数组,而不是 3d 数组。您的 JSON 对象由另一个数组中的 2 个元素数组组成。如果可以的话,让你的服务器只返回一个二维数组。否则你可以尝试:
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):
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: