加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax动态赋值highcharts柱形图

发布时间:2020-12-16 03:20:30 所属栏目:百科 来源:网络整理
导读:实现的效果为 1.jsp页面 !-- 引入highcharts官方js --script src="js/highcharts.js"/scriptscript$(function(){//获得hcharts数据并赋值$.ajax({ type:"post",url:rootPath+"/analyze/citySpeed.action",data : {"sendCityName":sendCityName,"receiverCity

实现的效果为


1.jsp页面

<!-- 引入highcharts官方js -->
<script src="js/highcharts.js"></script>
<script>
$(function(){

//获得hcharts数据并赋值
$.ajax({
	    type:"post",url:rootPath+"/analyze/citySpeed.action",data : {"sendCityName":sendCityName,"receiverCityName":receiverCityName},dataType:"json",cache:false,async:false,success:function(res){
			console.log(res);
			  var speed=[];//平均速度
			  var time=[];//平均用时
			  var carrierName=[];//横坐标
			for(var i = 0; i<res.length;i++){
		    	time.push(parseFloat(res[i].useTime));
		    	carrierName.push(res[i].carrierName);
		    	speed.push(parseFloat(res[i].speed));
		    };
		    console.log("============speed===========");
		    console.log(speed);
		    console.log(carrierName);
		    console.log(time);
  	     $('#container').highcharts({
  	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           chart: {
  	            type: 'column'
  	        },title: {
  	            text: '快递公司平均速度和平均用时'
  	        },subtitle: {
  	            text: '数据来源: wechat.com'
  	        },xAxis: {
  	            categories: carrierName,crosshair: true
  	        },yAxis: {
  	            min: 0,title: {
  	                text: '平均速度(km/h)'
  	            }
  	        },tooltip: {
  	            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
  	            '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',footerFormat: '</table>',shared: true,useHTML: true
  	        },plotOptions: {
  	            column: {
  	                pointPadding: 0.2,borderWidth: 0
  	            }
  	        },series: [{
  	            name: '速度(km/h)',data: speed
  	        },{
  	            name: '用时(h)',data: time
  	        }/*,{
  	            name: '时间(h)',data: [90,80,70,60,50,40,90,50]
  	        }*/]
  	    });
		},error:function(){
			
		}
	});

})
</script>


2.后台返回数据 返回map或者list都可以。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读