echarts 折线图 Ajax调用后台接口获取动态数据显示

不说废话,注意:不要忘了引入JS

<script src="https://cdn.bootcss.com/echarts/4.4.0-rc.1/echarts-en.min.js"></script>

折线图效果图:
在这里插入图片描述
代码:

<body>
    <div id="main" style="width: 100%;height:400px;"></div>
</body>


<script type="text/javascript">
		$(function(){
		$.ajax({
			type : 'post',
			url: baseUrl + "BIAction/buslineAttendance",//调用后台接口获取折线图上的数据
            dataType: "jsonp",
            success:function(result){
            	var dataList = result.dataList;//这个是Y轴的数据
            	var dateList = result.dateList;//这个是X轴的日期

            	//基于准备好的dom,初始化echarts实例
        		var myChart = echarts.init(document.getElementById('main'));
        		option = {
        				tooltip: {
       					  // formatter: '{b0}<br />{a0}:{c0}<br />{a1}:{c1}%',
       					  trigger: 'axis',
       					  formatter: function (dataList) {
							var html;       						  
       					    for(var i=0;i<dataList.length;i++){
       					        html = dataList[i].value+"%";//这里注意两个参数名不一样 data 和 date
       					    }
       					    return html;
       					  }
       					},
        				title: {
        	                text: '上座率'
        	            },
        	            grid: {
       				        left: '3%',
       				        right: '4%',
       				        bottom: '3%',
       				        containLabel: true
       				    },
        			    xAxis: {
        			        type: 'category',
        			        boundaryGap: [0, 0.01],
        			        data: result.dateList,
        			    },
        			    yAxis: {
        			        type: 'value'
        			    },
        			    color:["#7CBBF0"],
        			    series: [{
        			    	//color: '#275F82', //改变区域颜色
        			        data: result.dataList,
        			        type: 'line',
        			        smooth: true,
        			        showAllSymbol : true,
        			        lineStyle:{  //折线图上线的颜色
        			        	normal:{
        			        		color:"#7CBBF0",
        			        		width:3,
        			        	},
        			        },
        			        // 显示数值,折线图上的点
        			        itemStyle : { normal: {label : {show: true}}}
        			    }]
        			};
        			// 使用刚指定的配置项和数据显示图表。
        		    myChart.setOption(option);
            }
		})
	})
<script>

官方文档:https://echarts.apache.org/examples/zh/editor.html?c=line-simple

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七月吃橘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值