plotting JSON data using jqPlot

青春壹個敷衍的年華 提交于 2019-12-11 00:40:51

问题


I'm trying to plot some JSON Data using the jqPlot library within an HTML 5 app powered by jqMobile. I'm placing the following code within the 'body' of the html page. Is there something I'm missing here?

<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>

Edit: New Plot Method

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

回答1:


Of coarse there is a problem and the computer is again right. This is how your code should look like. You were defining success as if you were using ajax method, with getJSON success is passed as the 2nd parameter.

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

EDIT I spot also that you are not closing the ready function appropriately. It should be }); rather than just }.



来源:https://stackoverflow.com/questions/11141434/plotting-json-data-using-jqplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!