Apollo
Apollo

Reputation: 9054

plotting JSON data using jqPlot

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

Upvotes: 2

Views: 4557

Answers (1)

Boro
Boro

Reputation: 7943

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

Upvotes: 1

Related Questions