gpt4 book ai didi

jquery - 使用 jqPlot 绘制 JSON 数据

转载 作者:行者123 更新时间:2023-12-01 04:59:52 25 4
gpt4 key购买 nike

我正在尝试在由 jqMobile 提供支持的 HTML 5 应用程序中使用 jqPlot 库绘制一些 JSON 数据。我将以下代码放置在 html 页面的“正文”中。我在这里缺少什么吗?

<script>    
$(document).ready(function() {
// get the JSON data from server
$.getJSON("myspecialurl", function(data) {
success: function(data) {
plotData(data);
}
});
// plot the data
function plotData(data) {
ds = [];
$(data).find('latitude').each(function() {
ds.push([$(this).attr('answer'), parseInt($(this).attr('count'))]);
});
$.jqplot('chart1', [ds], {
seriesDefaults: {
renderer: $.jqplot.DonutRenderer
},
legend: {
show: true
}
});
}
}
</script>

编辑:新的绘图方法

function plotData( data ) {
// ds = [];
// $(data).find('latitude').each( function() {
// ds.push( [ $(this).attr('answer'), parseInt( $(this).attr('count') ) ] );
// } );
var array = data.contacts;


$.jqplot('chart1', array[0].latitude, {
seriesDefaults:{
renderer:$.jqplot.DonutRenderer
},
legend: {show:true}
});
}

最佳答案

当然,有问题,但计算机又恢复正常了。这就是您的代码应该的样子。您定义成功就像使用 ajax 方法一样,并且 getJSON success 作为第二个参数传递。

$.getJSON("myspecialurl", function(data) {
plotData(data);
});

编辑我还发现您没有正确关闭 ready 函数。它应该是 }); 而不仅仅是 }

关于jquery - 使用 jqPlot 绘制 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11141434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com