question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dataZoom with rangeMode: 'value' is broken

See original GitHub issue

Version

4.5.0

Steps to reproduce

When dataZoom is used with rangeMode: ‘value’, zoom gets reset immediately when data is added or changed. When rangeMode is left to the default value, it works. But rangeMode: ‘value’ is required since we need the chart to stay still when zoomed in and new data is added. This worked correctly in v4.2.1.

This is a slight adaptation of the dynamic data example that shows the problem. Just execute in the try editor, zoom in with the mouse wheel. When the next data updated is added, zoom, resets immediately.

function randomData() {
    now = new Date(+now + oneDay);
    value = value + Math.random() * 21 - 10;
    return {
        name: now.toString(),
        value: [
            [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'),
            Math.round(value)
        ]
    }
}

var data = [];
var now =  new Date(1997, 9, 3);
var oneDay = 24 * 3600 * 1000;
var value = Math.random() * 1000;
for (var i = 0; i < 1000; i++) {
    data.push(randomData());
}

option = {
    xAxis: {
        type: 'time',
    },
    yAxis: {
        type: 'value',
    },
    series: [{
        name: 'test',
        type: 'line',
        showSymbol: false,
        hoverAnimation: false,
        data: data
    }],
    dataZoom: [{
        type: 'inside',
        rangeMode: 'value'
    }]
};

setInterval(function () {
    for (var i = 0; i < 5; i++) {
        data.shift();
        data.push(randomData());
    }
    myChart.setOption({ series: [{ data: data }] });
}, 1000);

What is expected?

current zoom should remain unchanged

What is actually happening?

zoom is reset when data is added/changed

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
100pahcommented, Nov 20, 2019

@dr-itz

I think rangeMode: 'value' is not broken, but is a break change that I didn’t noticed. The previous behavior supports your usage but it is buggy in some cases. So I fixed it in the subsequent version, and clarified the definition of dataZoom.rangeMode. That makes your code work in the previous version but probably logically incorrect in the current definition.

Please try this code. I hope it can match your requirement:


var myChart = echarts.init(document.getElementById('main0'));

function randomData() {
    now = new Date(+now + oneDay);
    value = base++;
    return {
        name: now.toString(),
        value: [now, value]
    }
}

var data = [];
var base = 10;
var now = new Date(1997, 9, 3);
var oneDay = 24 * 3600 * 1000;
for (var i = 0; i < 100; i++) {
    data.push(randomData());
}

option = {
    tooltip: {
        confine: true
    },
    xAxis: {
        type: 'time',
    },
    yAxis: {
        type: 'value',
        scale: true
    },
    series: [{
        name: 'test',
        type: 'line',
        hoverAnimation: false,
        data: data
    }],
    dataZoom: [{
        type: 'inside'
        // Do not set rangeMode here
    }]
};

setInterval(function () {
    for (var i = 0; i < 5; i++) {
        data.shift();
        data.push(randomData());
    }
    myChart.setOption({
        series: [{ data: data }]
    });
}, 1000);

// Listen to dataZoom event, and set `startValue` and `endValue` to 
// fix the data window if zoomed.
myChart.on('dataZoom', function (event) {
    var dzCurrOpt = myChart.getOption().dataZoom[0];

    var dzOpt = {};
    dzCurrOpt.start > 0 ? (dzOpt.startValue = dzCurrOpt.startValue) : (dzOpt.start = 0);
    dzCurrOpt.end < 100 ? (dzOpt.endValue = dzCurrOpt.endValue) : (dzOpt.end = 100);

    myChart.setOption({
        dataZoom: dzOpt
    }, {lazyUpdate: true});
});

myChart.setOption(option);

And next, we should think of whether to add an option to support your case instead of the code above.

0reactions
echarts-bot[bot]commented, Jan 13, 2020

This issue is closed due to not being active. Please feel free to open it again (for the author) or create a new one and reference this (for others) if you have further questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

apache/echarts - dataZoom with rangeMode: 'value' is broken
Version 4.5.0 Steps to reproduce When dataZoom is used with rangeMode: 'value', zoom gets reset immediately when data is added or changed.
Read more >
echarts/pyecharts: dataZoom starts at 0 - python - Stack Overflow
AxisOpts( type_='value' ) datazoom_opts = opts.DataZoomOpts( type_='slider', start_value=1596705336000, end_value=1596706538000, ) ...
Read more >
Changelog - Apache ECharts
... [Fix] [dataZoom] Fallback to extent start/end when value or percent is invalid. ... [log] Fix log axis breaks a single data whose...
Read more >
[incubator-echarts] 08/16: feature: (1) support axis id reference ...
(except toolbox dataZoom) (3) enhance dataZoom to enable axis and dataZoom removal ... Possible values: 'filter' or 'empty' or 'weakFilter'.
Read more >
Python Figure Reference: layout.xaxis - Plotly
See `rangemode` for more info. If `range` is provided, then `autorange` is set to "False". autotypenumbers. Code: fig.update_xaxes(autotypenumbers=<VALUE>)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found