javascript - Displaying dynamic data in JQplot -


hello guys using jqplot display piechart. new jquery why kind hard me manipulate arrays in jquery.

this structure of arrays pass jquery , dynamic

array (size=8)   0 =>      array (size=1)       'baseball' => string '12.18' (length=5)   1 =>      array (size=1)       'basketball' => string '8.12' (length=4)   2 =>      array (size=1)       'boxing' => string '5.54' (length=4)   3 =>      array (size=1)       'golf' => string '6.64' (length=4)   4 =>      array (size=1)       'soccer' => string '36.90' (length=5)   5 =>      array (size=1)       'tennis' => string '27.31' (length=5)   6 =>      array (size=1)       'football' => string '2.21' (length=4)   7 =>      array (size=1)       'hockey' => string '1.11' (length=4) 

and want data display on pie chart. far code.

  $(document).ready(function(){          var sports = $('#sports').val();         // sports - variable holds data array          jquery.jqplot.config.enableplugins = true;         plot1 = jquery.jqplot('chart1',[sports],          [[['verwerkende fruedenstunde companaziert eine industrie', 9],['retail', 8], ['primaire producent', 7],          ['out of home', 6],['groothandel', 5], ['grondstof', 4], ['consument', 3], ['bewerkende industrie', 2]]], ` // put data array idont know  how`          {             title: '',              seriesdefaults: {             shadow: false,              renderer: jquery.jqplot.pierenderer,              rendereroptions: { padding: 2, slicemargin: 2, showdatalabels: true }               },          legend: { show:true, location: 'w' }         });     }); 

here solution

$(document).ready(function(){     var s = $.parsejson($('#sports').val());     var s1= [];     for(d in s)     {         (ix in s[d]) {             s1.push([ix , parsefloat(s[d][ix])])         }     }     console.log(s1)      jquery.jqplot.config.enableplugins = true;     plot1 = jquery.jqplot('chart1',[s1],     {         title: 'percentage of bets sport',          seriesdefaults: {         shadow: false,          renderer: jquery.jqplot.pierenderer,          rendereroptions: {              showdatalabels: true,             datalabelthreshold:0,             padding: 20,              slicemargin: 2,              diameter: 400,             showdatalabels: true }           },      legend: { show:true, location: 'ne' }     }); }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -