我试图使用jqplot来绘制从SQLite DB检索数据的条形图Phonegap - Android如何使用相同的代码为DB值。这个代码与静态数据的工作很好在标签内,但当我试图把这个代码在$('#pageid').live('pageinit',function(){});
然后它不工作。原因是什么?
<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], {
// The "seriesDefaults" option is an options object that will
// be applied to all series in the 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 a category axis on the x axis and use our custom ticks.
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
label:'NAMAZ',
ticks: ticks,
},
// Pad the y axis just a little so bars can get close to, but
// not touch, the grid boundaries. 1.2 is the 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>
您需要将其放在pageshow事件中。
只有在pageshow事件中才能正确计算页面高度。
所以像这样使用:
$(document).on('pageshow','#pageid',function(){});
如果你使用的是jQuery 1.9.1+版本,那么你不能使用live,因为它已经被弃用,不再存在。