echarts icon indicating copy to clipboard operation
echarts copied to clipboard

折线图: 当 X 与 Y 同时为 value 时,动态加载数据的画面不顺畅

Open qingweibinary opened this issue 10 years ago • 8 comments

option = {
    title : {
        text: '动态数据',
        subtext: '纯属虚构'
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        data:['最新成交价']
    },
    toolbox: {
        show : true,
        feature : {
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    dataZoom : {
        show : false,
        start : 0,
        end : 100
    },
    xAxis : [
        {
            type : 'value',
            scale: true
        }
    ],
    yAxis : [
        {
            type : 'value',
            scale: true,
            name : '预购量',
            max: 1200,
            min: 0,
            boundaryGap: [0.2, 0.2]
        }
    ],
    series : [
        {
            name:'最新成交价',
            type:'line',
            data:(function (){
                var res = [];
                var len = 0;
                while (len < 10) {
                    var n = [
                        len,
                        (Math.random()*10 + 5).toFixed(1)
                    ];
                    res.push(n);
                    len++;
                }
                return res;
            })(),
            animation: true,
        }
    ]
};
clearInterval(app.timeTicket);
app.count = 11;
app.timeTicket = setInterval(function (){

    var data0 = option.series[0].data;
    data0.shift();
    var lastData = data0[data0.length - 1];
    var x = [lastData[0] + 1, Math.round(Math.random() * 1000)];
    data0.push(x);

    myChart.setOption(option);
}, 2100);

把 series[0].animation 换成 false 之后会有所改善,但还是不理想,请问有办法改善吗?

Edit: xAxis.scale = true for more obvious visualization

qingweibinary avatar Feb 25 '16 09:02 qingweibinary

我试了下,不顺畅在哪?

pissang avatar Feb 25 '16 10:02 pissang

@pissang 有点难描述,我试下~ 当动态加载在最后一个 array element,感觉线图是重新画过,而不是往左移动

I am using chrome

qingweibinary avatar Feb 25 '16 10:02 qingweibinary

我的算法有点问题,我改改

Edit: 已改

qingweibinary avatar Feb 25 '16 10:02 qingweibinary

因为你数据中没有用 name 标识,程序中无法分辨新的数据跟上一份数据的对应关系

pissang avatar Feb 25 '16 10:02 pissang

请问怎么用 name 标识?

series[0].name
xAxis[0].name
yAxis[0].name

好像都不是?

qingweibinary avatar Feb 25 '16 10:02 qingweibinary

http://echarts.baidu.com/option.html#series-scatter.data.name

pissang avatar Feb 25 '16 12:02 pissang

Thanks, it fixed the problem, it would be great to have the same attribute document on series-line.data.name

Appreciate this awesome piece of software ~

qingweibinary avatar Feb 26 '16 01:02 qingweibinary

@qingweibinary 谢谢,发现 line 上是没加 name 的文档

pissang avatar Feb 26 '16 02:02 pissang