highcharts / highcharts-android

Android wrapper for Highcharts usage
Other
126 stars 30 forks source link

Show ResetZoom button programmatically #287

Open jacobmattsson opened 2 weeks ago

jacobmattsson commented 2 weeks ago

Hi!

I would like to show the ResetZoom button programmatically (after first having updated the extremes for the axis).

In JS, this can be done with chart.showResetZoom() (example: https://jsfiddle.net/Y6Mm6/2/)

But I can't find an API for doing the same thing in Android. :-(

Have I missed something?

Or is the only workaround to hide the (default) ResetZoom (with some theme) and then add a custom Button in Android (which overlays the chart)... But that feels awkward, especially to detect user-initiated zoom events and show the custom button! I would much rather reuse the (default) ResetZoom button and have an API for showing it programmatically!

Thanks!

MikolajMichalczak commented 1 week ago

HI @jacobmattsson!

Unfortunately, there isn't a native function in Android for programmatically showing the ResetZoom button. However, you can use JavaScript to achieve this. You can add an event to the xAxis that responds to setting extremes and triggers showResetZoom() through JavaScript:

val xAxis = HIXAxis()
xAxis.events = HIEvents().apply {
    setExtremes = HIFunction("function () { let chartDom = document.getElementById('container'); let chart = Highcharts.charts[Highcharts.attr(chartDom, 'data-highcharts-chart')]; chart.showResetZoom();}")
}
options.xAxis = ArrayList(listOf(xAxis))