javascript - window.onload get something wrong -
i got information others' api,but not take out,so write in input.
for(var x=0;x< loc.length;x++){ point[x]=new window.bmap.point(loc[x].lat, loc[x].lng); getloc(point[x],x); } function getloc(pt,i){ gc.getlocation(pt, function(rs){ var addcomp = rs.addresscomponents; var dd= addcomp.city + "" + addcomp.district + "" + addcomp.street; var addname="address"+i; var text="<input type='hidden' value="+dd+" name="+addname+" />"; $(".page-container").append(text); }); }
then problems happened.
here window.load
window.onload=function(){ var container_1_set={ chart: { type: 'column' }, title: { text: 'sudden turn' }, xaxis: { categories: [] }, yaxis: { min: 0, title: { text: 'sudden turn times' }, stacklabels: { enabled: true, style: { fontweight: 'bold', color: (highcharts.theme && highcharts.theme.textcolor) || 'gray' } } }, legend: { enabled:false }, tooltip: { formatter: function() { return '<b>'+ this.x +'</b><br>'+ this.series.name +': '+ this.y +'<br>'+ 'count: '+ this.point.stacktotal; } }, plotoptions: { column: { cursor:'pointer', stacking: 'normal', datalabels: { enabled: true, color: (highcharts.theme && highcharts.theme.datalabelscolor) || 'white' }, point:{ events:{ click:function(){ location.href="road_list.php?road="+this.category; } } } } }, series: [{ name: 'sudden turn', data: [ <?php foreach ($result["data"] $item) {?> { y:<?php echo $item["time"];?>, color:"<?php echo $item["color"];?>", }, <?php } ?>] }] }; var cat=[]; for(var i=0;i<10;i++){ var aa=$("input[name='address"+i+"']").val(); cat.push(aa); } console.log(cat); container_1_set.xaxis.categories=cat; $('#container_1').highcharts(container_1_set); };
if press f5 button,it can value , work.
when clicking on column of chart,the variable cat undefined.
window load not required. instead have document ready. no need use both.
Comments
Post a Comment