-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Data grouping for large datasets #4053
Comments
This looks like an interesting feature that could form the basis of a lot of features. I feel that this could live as a plugin that ships from the main repository but that isn't included in the main build (due to size requirements that this introduces). I'm happy to look at a PR that starts these features out. Another option is to do min max decimation which at most has 4 points per pixel |
Thank you for your quick answer @etimberg I am just getting started with chartjs (but I already love it) could you point some hints to get started with this? I have to get this implemented anyway and I'd be happy to collaborate. |
Some examples of plugins are: https://github.com/chartjs/chartjs-plugin-zoom https://github.com/chartjs/chartjs-plugin-annotation The plugin docs are: https://github.com/chartjs/Chart.js/blob/master/docs/developers/plugins.md What I think you would need to do is to hook into |
I'll make sure to follow up here when I make some progress on this |
This would be highly beneficial for us too. Thanks for looking into this. |
Another vote for this feature here |
@jesusgp22 Did you ever implement a plugin for this? This would be super helpful right now. |
There is something like this, maybe you can use it as a starting point: |
Because I had massive performance issues with charts containing tens of thousands of data points, I implemented pretty much what got suggested here. Thought I'd share it after I found this topic. The following code can be registered globally as a default plugin via
Disclaimer:It's only a proof of concept and therefore does only work with time points (millis, not date objects) on the x axis. Also it assumes there is only one x axis, so it ignores limits of other axes. Updating (adding/removing) data only works if you hold the original data array references and work with them. The chart options datasets obviously cannot be used for that anymore, since they only hold the view values. How it works and what it does:First everything outside the visible range gets cut (massive performance gain on its own, this should happen natively inside Chart.js if you ask me), then the remaining data points get reduced to 800 averaged points of the data that gets dropped. This number can be configured via |
@neon-dev I am getting this error when added your snippet:
Any hints? |
Since you did not provide a fiddle or further information about your data and chart version, I created a working fiddle using my plugin: Hope it helps. As I already said, it most likely needs to be modified to work for your use case. |
@neon-dev Thanks for your code. I am trying to adapt it, but my axis is numerical (linear), not time. How do I find min and max values on the x axis? |
@khumarahn Regular min and max values are stored in the ticks option per axis, so you need to change time to ticks:
Quick example: https://jsfiddle.net/donyxzqz/4/ (you should rename other variables which are still called or referring to |
thanks! I found also that |
@neon-dev are you considering including this into a plugin ? |
@PodaruDragos sorry, no plans. Best would be to integrate the main performance boost (data truncation outside the visible area) directly into Chart.js with a PR in my opinion, but I don't have the time and experience with the Chart.js source for it. If we had that, the grouping feature could be a plugin on its own or also become a native feature. |
@neon-dev i am willing to help if i can, i don't have any experience with the library, but this seems like a good ideea |
any progress on this? |
Any update? |
Chart.js v3 should be much faster, but if you want something even faster than that, here's a shameless plug: https://github.com/leeoniya/uPlot |
Yes, this has actually been implemented for line charts in v3: Chart.js/src/elements/element.line.js Line 87 in e259366
It hasn't been implemented for other chart types yet |
Thank you! |
@benmccann are there any benchmarks for how fast this is compared with master ? |
development on v3 is occurring on we've made a lot of improvements in the most recent versions. 2.9.3 is a lot faster than 2.8. I would recommend checking out our new performance docs for other tips on speeding up your charts: https://www.chartjs.org/docs/latest/general/performance.html we're working on deploying a benchmark currently, but 3.x is currently somewhere around 2-3x faster than 2.x. we're still working on additional improvements that should make at least another 2-3x faster |
Based on the suggestions here I have written a plugin that displays only one data point per pixel. In my example fiddle, the plugin seems to be 2-8 times faster than plain chart.js 2.9.4, depending on the amount of data and canvas size. https://jsfiddle.net/dudelkuchen/xboa584h/30/ https://github.com/dudelkuchen/chartjs-plugin-largedatasets |
@etimberg Why was this closed? That PR didn't even solve the original users suggestion. |
It's recommended to do this in a plugin. We added the hooks necessary to allow such a plugin. We also added data decimation in core: https://www.chartjs.org/docs/latest/configuration/decimation.html |
Expected Behavior
Other charting libraries automatically group series data instead of rendering every single point (example: http://www.highcharts.com/stock/demo/data-grouping) and here is a detailed explanation of how it's done in amcharts: https://www.amcharts.com/kbase/understanding-data-grouping-of-stock-chart/
Possible Solution
The solution outlined by highcharts.js and amcharts are a bit different:
Context
Often data visualizations require to render thousands of points, this is not necesary becase:
The text was updated successfully, but these errors were encountered: