jquery - jqplot not working for dynamic data -
i trying use jqplot plot bar chart graph of data retrieving sqlite db phonegap - android how use same code db values. code static data working fine inside of tag when m trying put code inside of $('#pageid').live('pageinit',function(){});
not working. what's reason?
<head> <script type="text/javascript" src="js/lib/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/lib/jquery.jqplot.js"></script> <script type="text/javascript" src="js/lib/jqplot.barrenderer.js"></script> <script type="text/javascript" src="js/lib/jqplot.categoryaxisrenderer.js"></script> <script type="text/javascript" src="js/lib/jqplot.pointlabels.js"></script> <link rel="stylesheet" href="css/lib/jquery.jqplot.css"/> <script type="text/javascript"> var s1 = [10,0,0,0,0]; var s2 = [0,20,0,0,0]; var s3 = [0,0,30,0,0]; var s4 = [0,0,0,25,0]; var s5 = [0,0,0,0,0]; var ticks = ['fajr', 'zohar', 'asr', 'maghrib','isha']; var plot1 = $.jqplot('chart1', [s1, s2, s3,s4,s5], { // "seriesdefaults" option options object // applied series in chart. seriesdefaults:{ title:'namaz vs missingprayer', renderer:$.jqplot.barrenderer, rendereroptions: {filltozero: true} }, series:[ {label:'fajr'}, {label:'z'}, {label:'a'}, {label:'m'}, {label:'i'} ], legend: { show: true, placement: 'outsidegrid' }, axes: { // use category axis on x axis , use our custom ticks. xaxis: { renderer: $.jqplot.categoryaxisrenderer, label:'namaz', ticks: ticks, }, // pad y axis little bars can close to, // not touch, grid boundaries. 1.2 default padding. yaxis: { min:0, label:'missing prayers', pad: 1.05, tickoptions: {formatstring: '%d'} } } }); }); </script> </head> <body> <div data-role="page" id="graph"> <div data-role="content"> <div id="chart1" style="width:600px; height:350px;"></div> </div> </div> </body> </div>
you need put inside pageshow event.
page height can calculated correctly during pageshow event.
so use this:
$(document).on('pageshow','#pageid',function(){});
also if using jquery version 1.9.1+ can't use live because deprecated , no longer exist.