Home >Web Front-end >JS Tutorial >ECharts3 implements the operation of dynamic data + time axis

ECharts3 implements the operation of dynamic data + time axis

一个新手
一个新手Original
2017-09-22 09:38:2610885browse

ECharts3 implements the operation of dynamic data + time axis
The dynamic data + time coordinate axis instance in the ECharts3 official website has been modified. The X-axis is the current time, and the data is accumulated.

You can paste it in the code box in the ECharts3 instance to see the effect directly.

function randomData() {
    now = new Date(+now + 1000);
    value = value + Math.random() * 21 - 10;    
    return {
        name: now.toString(),
        value: [
            now,            
            Math.round(value)
        ]
    }
}var data = [];var now = new Date();var value = Math.random() * 1000;

option = {
    title: {
        text: '动态数据 + 时间坐标轴'
    },
    tooltip: {
        trigger: 'axis',
        formatter: function (params) {
            params = params[0];            
            var date = new Date(params.name);            
            return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1];
        },
        axisPointer: {
            animation: false
        }
    },
    xAxis: {
        type: 'time',
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        boundaryGap: [0, '100%'],
        splitLine: {
            show: false
        }
    },
    series: [{
        name: '模拟数据',
        type: 'line',
        showSymbol: false,
        hoverAnimation: false,
        data: data
    }]
};
setInterval(function () {
        //data.shift();
        data.push(randomData());
    myChart.setOption({
        series: [{
            data: data
        }]
    });
}, 1000);

The above is the detailed content of ECharts3 implements the operation of dynamic data + time axis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn