amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.16k stars 322 forks source link

Suggestion: Allow to switch between data grouping and downsampling with LTTB #2899

Closed EmaGht closed 4 years ago

EmaGht commented 4 years ago

Hi, First of all let me tell you i love the library. I've been using Data based series a lot and found out that Data Grouping isn't really representative of a time series when it's grouped... let me show what i mean.

Consider this: 6 months of hourly values (~4500 values) without any kind of downsampling / grouping:

image

Now, this is the same series, grouped up with amcharts grouping capabilities and a groupCount of 1500

image

And this is the same series downsampled with LTTB algorithm (https://pastebin.pl/view/5e61bb7f) and a threshold of 1500:

image

I've also noticed that with series with a lot of ups and downs, amcharts tends to group those ups and downs inside the same bucket creating only one up-down for many of the original series.

My suggestion is to make native the fact of switching the grouping algorithm between a grouping and a downsampling or to make it possible to tell amcharts which algorithm to use. I've already checked out and tried this: https://www.amcharts.com/docs/v4/concepts/axes/date-axis/#Custom_aggregate_functions but because LTTB acuatlly changes the series instead of aggregating it I didn't find a way to make things work...

Hopefully this piques your interest :D I think it would be great if such a feature would make it live in amcharts!

martynasma commented 4 years ago

Thanks for the suggestion.

I'm afraid we don't have any plans to implement this in the core package. Certainly not as part of the built-in grouping mechanism. That would introduce the whole new level of complexity and fuzzy logic to an already complicated part.

That said, I can see how it could be implemented using data pre-parsing. E.g. when beforedatavalidated event on chart kicks in, a LTTB mechanism kicks in and downsamples actual source data, and the chart is none the wiser.

If you'd like to take a stab to implement that, here's a doc that deals with source data manipulation before it gets to the chart: https://www.amcharts.com/docs/v4/tutorials/manipulating-chart-data/

EmaGht commented 4 years ago

I'll probably take a look eventually, as the need arises!

For now I'll close the issue, thank you for pointing me to a possible solution!