apexcharts.js icon indicating copy to clipboard operation
apexcharts.js copied to clipboard

Bumpy graphs with the "smooth" line option

Open Narcha opened this issue 3 years ago • 16 comments

Is your feature request related to a problem? Please describe. The "smooth" line option's interpolation produces a bumpy line for linearly increasing data.

Describe the solution you'd like It should produce a straight line, like chart.js.

Describe alternatives you've considered If possible, use a different interpolation algorithm that produces smoother output lines.

Additional context This is a test dataset with linearly increasing values. chart.js produces a straight line, ApexCharts adds a bump on every data point. This issue is always noticable if a dataset has repeated changes in the same direction (multiple increases or decreases after eachother) apexcharts interpolation

Narcha avatar Aug 18 '20 15:08 Narcha

This is especially apparent when trying to do something like plotting a regression line over data. Screen Shot 2020-11-05 at 12 58 26 PM

Fingel avatar Nov 05 '20 20:11 Fingel

I think catmullRom looks much smoother. Even though there are no plans for adding more curve options (#821), how feasible is it to change the interpolation algorithm behind smooth?

fintara avatar Jan 06 '21 06:01 fintara

I am loving ApexCharts, but the line smoothing is a huge issue for dashboard creation. I've never seen a chart presented like this in any capacity, whether it be in academia or corporate. Is there any plan for improving the smooth line to something closer to ggplot, or is this a non-starter for the devs?

gbenchanoch avatar Sep 14 '21 12:09 gbenchanoch

I am loving ApexCharts as well but the line interpolation really needs some extra love! Here's an example of a sine function with linear ('straight') interpolation versus 'smooth' interpolation (green line)

straight: imagem

smooth: imagem

As you can see, the straight line option actually looks smoother than the smooth line option for the sinuous line. It's a shame there are no plans to add more curve options :'(

chipimix avatar Nov 11 '21 11:11 chipimix

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jan 10 '22 14:01 github-actions[bot]

Bumping this issue to keep it alive. I think it's essential for ApexCharts to offer smooth lines. The current "smooth" implementation is worthless, for anything but controlled examples, and straight lines only look good if you happen to have lots of smooth data points.

daviddavid avatar Jan 10 '22 14:01 daviddavid

Any update on this? Maybe there is a setting we are missing?

LukasGirsch avatar Mar 04 '22 13:03 LukasGirsch

I'd also love for this to be improved. Currently having to opt for straight lines, sadly :(

JorgenSolli avatar Apr 23 '22 19:04 JorgenSolli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 23 '22 14:06 github-actions[bot]

Bumping this for the same reasons as last time

Narcha avatar Jun 24 '22 08:06 Narcha

I think that Monotone cubic interpolation would be a much better interpolation for apexcharts. It respects extrema and since --the chosen tangent (before correction) is parallel to the line joining the two neighboring points,-- it avoids squiggling in the example cases here.

EDIT: my memory was imprecise; the tangent slope at a non-extremum point is the mean of the slope of the neighboring straight lines in a non-smooth graph. The conclusion still holds, and this is equivalent if the points are equally distant from each other along the x axis.

FrnchFrgg avatar Jul 14 '22 13:07 FrnchFrgg

Note that https://github.com/apexcharts/apexcharts.js/blob/main/src/charts/Line.js#L615 says that the algorithm apexcharts uses is based on chartist which implements monotone cubic interpolation there: https://github.com/gionkunz/chartist-js/blob/develop/src/scripts/interpolation.js#L240

Maybe that interpolation was added afterwards, but since the apexcharts dev seem familiar with the chartist implementation it may help implementing monotone cubic interpolation here. I tried to make sense of the apexcharts smoothing code, but AFAICT as it is it only passes two points to the smoothing routine (the two extremities of a segment) where monotone cubic needs four (the leftmost point of the segment to the left, and the rightmost point of the segment to the right, in addition to those already passed).

AFAICT again, the current apexcharts smoothing code handles segments separate from each other, and thus has to chose an horizontal tangent for continuity purposes. This is of course the best when the point is an extremum, but it is also the reason for the artifacts seen here.

FrnchFrgg avatar Jul 14 '22 13:07 FrnchFrgg

Note that https://github.com/apexcharts/apexcharts.js/blob/main/src/charts/Line.js#L615 says that the algorithm apexcharts uses is based on chartist which implements monotone cubic interpolation there: https://github.com/gionkunz/chartist-js/blob/develop/src/scripts/interpolation.js#L240

Maybe that interpolation was added afterwards, but since the apexcharts dev seem familiar with the chartist implementation it may help implementing monotone cubic interpolation here. I tried to make sense of the apexcharts smoothing code, but AFAICT as it is it only passes two points to the smoothing routine (the two extremities of a segment) where monotone cubic needs four (the leftmost point of the segment to the left, and the rightmost point of the segment to the right, in addition to those already passed).

AFAICT again, the current apexcharts smoothing code handles segments separate from each other, and thus has to chose an horizontal tangent for continuity purposes. This is of course the best when the point is an extremum, but it is also the reason for the artifacts seen here.

Thanks for this! I might jus be migrating to Chartist for this. At least until, hopefully, this is added to ApexCharts... lineSmooth: Chartist.Interpolation.monotoneCubic seems to work wonderfully with my dataset.

JorgenSolli avatar Jul 15 '22 07:07 JorgenSolli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 13 '22 14:09 github-actions[bot]

This is still relevant.

Narcha avatar Sep 13 '22 14:09 Narcha

Is there any way to contribute to this by implementing alternative smoothing algorithms, so one can choose one like in chartist? (lineSmooth: Chartist.Interpolation.monotoneCubic)

JaspervanderSter avatar Sep 15 '22 08:09 JaspervanderSter

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Nov 14 '22 14:11 github-actions[bot]

This is still relevant.

JorgenSolli avatar Nov 14 '22 14:11 JorgenSolli

Thanks for a great charting library! Would be awesome with additional interpolation options in order to communicate well the underlying data

kimdanielarthur avatar Nov 22 '22 01:11 kimdanielarthur

Yes, a real smoothing would be appreciated, we have to rely on the straight lines for now

Tiagolm avatar Jan 18 '23 17:01 Tiagolm

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Mar 20 '23 14:03 github-actions[bot]

This is still relevant.

Narcha avatar Mar 20 '23 14:03 Narcha

So do I understand correctly that one of the holdups on this is the amount of data getting passed to the interpolation routine, as FrnchFrgg mentioned here? So a new interpolation option would require a refactor that allows two extra data points?

Adding my voice to those affected by this issue and looking forward to a solution. 🙂

PeterMarkley-iTickets avatar May 15 '23 20:05 PeterMarkley-iTickets

Looking forward to a solution! I might not be able to use this library without the option of a smoother line.

katemccubbins avatar Jun 01 '23 20:06 katemccubbins

The same here, I am building a chart for financial application, users for sure want to see the trend is going upward without the bumps :)

aaronguostudio avatar Jul 31 '23 16:07 aaronguostudio

The same here, I am building a chart for financial application, users for sure want to see the trend is going upward without the bumps :)

I ended up using Chart.js for my application. The lines were perfect!

katemccubbins avatar Jul 31 '23 18:07 katemccubbins

A new option has been added since v3.42.0.

stroke: {
  curve: "monotoneCubic"
}

https://apexcharts.com/docs/options/stroke/#curve

junedchhipa avatar Sep 04 '23 09:09 junedchhipa

Will it be possible in the future to have null values in the data for the line graph without it falling back from 'monotoneCubic' to 'straight'?

OliverRomhagen avatar Sep 05 '23 10:09 OliverRomhagen