Closed shredder11 closed 5 years ago
I am afraid that I am not quite sure about what you expect exactly. I guess that you what to do something about data in according to the zoom window, isn't it? In the sample (https://github.com/ecomfe/echarts/blob/master/test/connect-manually.html) you mentioned you can see that in the zoom event start
and end
can be obtained, which is the values on the axes that dataZoom
controlled, and can be used to filter the original data and get the items in the zoom window. For example,
var originalData = [
[12, 323, 443],
[44, 33, 77],
[6, 78, 13],
[12, 13, 94]
];
chart.setOption({
...,
dataZoom: {
xAxisIndex: 0,
...
},
series: [{
...,
data: originalData
}]
});
chart.on('dataZoom', function (params) {
var start = params.batch[0].start;
var end = parasm.batch[0].end;
var dataInWindow = originalData.filter(function (item) {
return item[0] >= start || item[0] <= end;
});
// do something others ...
});
it works but when I apply a function after that (dividing all the values in dataInWindow by the initial value => thus rescaling the data on window) it takes forever to compute which means I can't use as a production tool for obvious reasons. do you happen to know whether some shortcuts are available?
thank you for your quick answer
From what I see dataZoom event start and end params is percentage values of the total range of a data array. So a calculation can be made of at what indexes in a data array the zoom window is set. Something like
var start_index=Math.round(data.values.length*(param.start/100))-1;
var end_index=Math.round(data.values.length*(param.end/100))-1;
Another way to do it is using the current chart instancexAxis[0].rangeStart/rangeEnd
Then filter the original data array against the xAxis times. This only works for timeseries, just thought someone might find it useful. Here's an example:
const DATA = [[1319846400000, 0.0911189678976507], [1319932800000, 0.088428855674535],…]
onDataZoom(zoom, chart) {
const option = chart.getOption()
const start = option.xAxis[0].rangeStart
const end = option.xAxis[0].rangeEnd
const cropped = DATA.filter(r => r[0] > start && r[0] < end)
const transformed = your_transform_function(cropped)
option.series[10].data = transformed
chart.setOption(option)
}
@dan5000 I tired to replicate your example, but my when I assign new series, my dataZoom
line disables.
Can you have a look at this issue please
Sadly it seems that the workaround proposed by @dan5000 doesn't work anymore with echarts 5. xAxis[0].rangeStart/rangeEnd
are undefined.
myChart.on('datazoom', (evt) => { const option = myChart.getOption() console.log(option.xAxis[0].data[option.dataZoom[0].startValue],option.xAxis[0].data[option.dataZoom[0].endValue]) });
Im using vue echarts and this is how im changing the startValue/endValue instead:
this.option.dataZoom[indexOfTheAxisYouWantToSetTheRange].startValue = number/date/string accepted this.option.dataZoom[indexOfTheAxisYouWantToSetTheRange].endValue= number/date/string accepted
Is there any way to apply this in React? Any experience?
One-line summary [问题简述]
How to Dynamically change existing data (data contained in the shown window) on Zoom event?
Version & Environment [版本及环境]
Expected behaviour [期望结果]
asking here for lack of a better place: I'd like to know whether there was a get the values referring to the Zoom Area and apply a function on them. in my case it would be very nice to have if I could access the data. in the API there does not seem to be an explicit way so I was hoping for some DOM coordinates (like series.data.values[0])
specifically, I was looking at this: https://github.com/ecomfe/echarts/blob/master/test/connect-manually.html
ECharts option [ECharts配置项]
Other comments [其他信息]
FYI: Echarts is, by all accounts, exceptional work