echarts封装让data数据自己动起来

一直循环播放 tooltip (data数据盒子)
function dynamic(echart,length) {
	//播放所在下标
	    let index = 0;
	    setInterval(function() {
	        echart.dispatchAction({
	            type: 'showTip',
	            seriesIndex: 0,
	            dataIndex: index
	        });
	        index++;
	        if(index > length) {
	            index = 0;
	        }
	    }, 1000);
	}
封装的data数据变换每次刷新都不同
	function random(max) {
	    let ran = Math.random()*max;
	    return parseInt(ran,10);
	}
#实例化option后面使用

dynamic(chart,4);
//{ chart: 获取html节点 。 4: 是data的数据量 eg: data: [‘1月’, ‘2月’, ‘3月’, ‘9月’] .}

具体使用如下:简单 柱形图 tooltip动起来可观性更加炫

	function chargePile() {
    	//严格意义上讲如果是vue就不能用init了!
	    let cpChart = echarts.init(document.querySelector(".charge-pile .chart"));
	    let cpOption = {
	        tooltip: {  //这里是平时鼠标移入就会出现data数据盒子,现在是自动循环播放这个盒子
	            trigger: 'axis',
	            axisPointer: {
	                type: 'line'
	            },
	            borderColor:'#363C44',
	            backgroundColor: "rgba(54,60,68,0.8)",
	            textStyle: {
	                color: "#fff"
	            }
	        },
	        grid: {
	            left: '3%',
	            right: '4%',
	            bottom: '3%',
	            containLabel: true
	        },
	        xAxis: {
	            type: 'category',
	            axisTick: {
	                alignWithLabel: true
	            },
	            axisLabel: {
	                show: true,
	                interval:0,
	                textStyle: {
	                    color: '#868792'
	                }
	            },
	            data: areaName,
	        },
	        yAxis: {
	            name: '单位:个',
	            nameTextStyle:{
	                color:"#038FBB"
	            },
	            type: 'value',
	            axisLabel: {
	                show: true,
	                textStyle: {
	                    color: '#868792'
	                }
	            },
	            axisTick: {
	                show: false
	            }
	        },
	        series: [
	            {
	                type: 'bar',
	                data: [
	                    random(250), random(250), random(250),
	                    random(250), random(250), random(250),
	                    random(250), random(250), random(250)
	                    //这里random是我封装的每次刷新data数据index都会发生改变
	                ],
	                itemStyle: {
	                    normal: {
	                        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
	                            offset: 0,
	                            color: "#01ccfe" // 0% 处的颜色
	                        }, {
	                            offset: 0.5,
	                            color: "#08a4fa" // 50% 处的颜色
	                        }, {
	                            offset: 1,
	                            color: "#1268f3" // 100% 处的颜色
	                        }], false)
	                    }
	                }
	            }
	        ]
	    };
	    cpChart.setOption(cpOption);
	    window.addEventListener("resize", function() {
	        cpChart.resize();
	    });
	    dynamic(cpChart,9);   //一直循环播放data数据,可观性非常棒!
	}

在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值