Reputation: 98
I am developing an Apache ECharts based application that is supposed to display a very large number of data points in a line chart. There may well be millions of data points. The X-axis represents the time and the Y-axis the value. The "xAxis->data" option is not used. The series is configured as follows:
let option = {
series: [
type: 'line',
data: [[time1, value1], [time2, value2], ...]
]
}
As long as the viewport (DataZoom) is scaled in and, let's say, shows less than 4000 points, then the left/right scrolling and zooming of the chart behaves smoothly.
However, if you zoom out and the chart has to display more than 10,000 data points, then it starts to become sluggish.
It is always the case that the further you zoom out, the fewer data points are required, to display a graph in a meaningful way. As the number of data points does not currently change, the system is overloaded.
In order to keep the graph fluid and performant at all times, it is advisable to "thin out" the data, e.g. by using the Ramer-Douglas-Peucker algorithm: https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
Now to my questions:
If not, then the approach could be to pass a reduced set of data to Echarts. So that ECharts can/should constantly work with 2,000 - 5,000 data points, regardless of whether you zoom in or out.
In this case, the ECharts series data should be replaced when zooming and scrolling, so that these 2,000 - 5,000 data points are always used for a specific time range.
Ideally, the DataZoom slider should take the entire temporal range into account, so that the user does not notice anything when scrolling and zooming, that the data is constantly changing in the background.
Upvotes: 1
Views: 2196
Reputation: 2551
'line'
there exists a property sampling which does what you are asking for. I dont know how well it is performing tho.xAxis
(show: false
)type
to 'category'
and fill it with some data that represents the xAxis wellconst data = [[0,150], [1,230], [2,224], [3,218], [4,135], [5,147], [6,260]];
option = {
dataset: [
{source: data}
],
xAxis: [
{type: 'value'},
{
type: 'category',
show: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
}
],
yAxis: {
type: 'value'
},
dataZoom: {type: 'slider', xAxisIndex: 1, realtime: false},
series: [
{
type: 'line'
}
]
};
myChart.on('dataZoom', function(params) {
// do your computation and replace dataset
const startIndex = Math.floor(params.start * 0.01 * 7);
const endIndex = Math.floor(params.end * 0.01 * 7);
const newData = data.slice(startIndex, endIndex);
myChart.setOption({dataset: [{source: newData}]});
});
Upvotes: 0