解决setInterval函数传参问题

修改window.setInterval函数,使其可以接收参数

var __sto = setInterval;
window.setInterval = function (callback, timeout, param) {
	var args = Array.prototype.slice.call(arguments, 2);
    var _cb = function () {
    	 callback.apply(null, args);
    }
    return __sto(_cb, timeout);
}

以绘制echarts函数为例:

var interval1 = window.setInterval(Abnormal, 1000, xData,yData);
setTimeout(function () {
	clearInterval(interval1)
}, 5000)

echarts函数:

function Abnormal(xValue, yValue) {
	var n = echarts.init(document.getElementById('n'));

	var option = {
    	//backgroundColor: '#0E204A',
        tooltip: {
        	trigger: 'axis',
            axisPointer: {
            lineStyle: {
            	color: {
                	type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                    	offset: 0,
                        color: 'rgba(255,255,255,0)' // 0% 处的颜色
                    }, {
                        offset: 0.5,
                        color: 'rgba(255,255,255,1)' // 100% 处的颜色
                    }, {
                         offset: 1,
                         color: 'rgba(255,255,255,0)' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            },
        },

    },
    grid: {
    	top: '10%',
        left: '1%',
        right: '1%',
        bottom: '5%',
        borderWidth: 0,
        containLabel: true
    },
    xAxis: [{
	        type: 'category',
	        boundaryGap: true,
	        axisLine: { //坐标轴轴线相关设置。数学上的x轴
	        	show: true,
	            lineStyle: {
	            	color: '#585F90'
	            },
	        },
	        axisLabel: { //坐标轴刻度标签的相关设置
	        	textStyle: {
	            color: '#585F90',
	            margin: 15,
	        },
		},
        axisTick: {
        	show: false,
        },
        data: xValue //横坐标日期    
    }],
    yAxis: [{
    	type: 'value',
        min: 0,
        // max: 140,
        splitNumber: 4,
        splitLine: {
        	show: true,
            lineStyle: {
            	color: 'rgba(255,255,255,0.1)'
            }
        },
        axisLine: {
        	show: false,
        },
        axisLabel: {
        	show: false,
            margin: 20,
            textStyle: {
            	color: '#d1e6eb',
            },
        },
        axisTick: {
        	show: false,
        },
        splitLine: {
            show: false
        },
     }],
     series: [{
     	name: '注册总量',
        type: 'line',
        smooth: true, //是否平滑曲线显示
        symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
        showAllSymbol: true,
        // symbol: 'image://./static/images/guang-circle.png',
        symbolSize: 8,
        lineStyle: {
        	normal: {
            	color: "#4A83E3", // 线条颜色
            },
            borderColor: '#f0f'
        },
        label: {
        	show: true,
            position: 'top',
            textStyle: {
            	color: '#fff',
             }
		},
		itemStyle: {
        	normal: {
	        	color: "#4A83E3",
                borderColor: '#fff', //拐点边框颜色
                borderWidth: 3
            }
       },
       tooltip: {
       		show: false
      },
      areaStyle: { //区域填充样式
      		normal: {
           	//线性渐变,前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’,则该四个值是绝对像素位置。
             color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
             		offset: 0,
                    color: 'rgba(0,150,239,0.3)'
             	 },
             	 {
                    offset: 1,
                    color: 'rgba(0,253,252,0.3)'
              	 }
             ], false),
             shadowColor: 'rgba(53,142,215, 0.9)', //阴影颜色
             shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
             }
      },
     		 data: yValue //纵坐标数值
	}]


	};

	n.setOption(option);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值