highcharts-android icon indicating copy to clipboard operation
highcharts-android copied to clipboard

HiChartView GestureListener

Open caifuentes opened this issue 3 years ago • 5 comments

Hi,

Is there a GestureListener that we can use for the HiChartView?

I've tried to use hiChartView.setOnTouchListener but it's not being called..

The behavior that we're trying to achieve here is to call an API when user swipe left or right then display new set of data in the chart. How can we check if users swipe left or right in the HiChartView?

Thank you.

caifuentes avatar Dec 09 '21 13:12 caifuentes

Hi @caifuentes ! Thanks for the question. Since Highcharts Android library is a wrapper of original JS library it does not support swipe events. The OnTouchListener is not being called because the chart itself is intercepting all events (e.g. for example if you enable zoom in your chart then you could swipe on it to move around the data).

However, if your project requires swipe gestures for API call I would create an invisible/transparent overlay view on your chart (matching its size), move it to the foreground and attach your implementation of swipe event on it. This approach has an disaventage though because that way you will loose all chart interactions like data labels popup on data click and so on.

soommy12 avatar Dec 09 '21 19:12 soommy12

Can we use the redraw event instead when we swipe left or right to pan the chart, so we can make an API call if we reach a certain value on x-Axis? As I understand the redraw event is triggered in panning or zooming situations.

balkango avatar Feb 06 '23 12:02 balkango

Yes you can use the redraw event @balkango

soommy12 avatar Feb 08 '23 09:02 soommy12

@soommy12 but how can we use "redraw" because the main problem is, we are not making a API call for the new separate set of data, we are making a new API call to add our currently shown set of data within a date/hour limit, not for live data or something.

kaanakell avatar Feb 08 '23 10:02 kaanakell

The redraw event can be triggered after any action that will result any visible change on the graph, including adding/removing one or multiple series/data point, modifying x or y values of the existing data points, panning, zooming, etc. as the graph will be redrawn from scratch with the included change. At the end of the redraw process, redraw event is triggered and the attached callback will be executed. It is independent of what kind of data is shown on the graph or what you will do after redrawing. In the callback (HIFunction) you can make any API call to get new data and add them to the existing series or as a new series, completely up to you:

chart.setEvents(new HIEvents()); chart.getEvents().setRedraw(new HIFunction( f -> { if (...) // condition to make the API call { // make API call // add new data to an existing series or add new series. } }, new String[] {"x", "y"} ));

You need to be careful with the if condition to prevent infinitely recalling the content of the if block.

Can you confirm or correct above @soommy12, please?

balkango avatar Feb 08 '23 11:02 balkango

The redraw event can be triggered after any action that will result any visible change on the graph, including adding/removing one or multiple series/data point, modifying x or y values of the existing data points, panning, zooming, etc. as the graph will be redrawn from scratch with the included change. At the end of the redraw process, redraw event is triggered and the attached callback will be executed. It is independent of what kind of data is shown on the graph or what you will do after redrawing. In the callback (HIFunction) you can make any API call to get new data and add them to the existing series or as a new series, completely up to you:

chart.setEvents(new HIEvents()); chart.getEvents().setRedraw(new HIFunction( f -> { if (...) // condition to make the API call { // make API call // add new data to an existing series or add new series. } }, new String[] {"x", "y"} ));

You need to be careful with the if condition to prevent infinitely recalling the content of the if block.

Can you confirm or correct above @soommy12, please?

Generally it's true, setRedraw() fires when the chart is redrawn, either after a call to chart.redraw() or after an axis, series or point is modified with the redraw option set to true.

MikolajMichalczak avatar Apr 29 '24 10:04 MikolajMichalczak