NativeScript / nativescript-ui-charts

NativeScript wrapper around HiCharts library
Apache License 2.0
26 stars 6 forks source link

chart.setOptions not working as expected on Android #26

Closed cjohn001 closed 3 years ago

cjohn001 commented 3 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

It seems like setOptions is broken on Android. I expect that setOptions can be used to set an entire new chart into a chart view. For example setOptions('options with pie chart') followed by setOptions(options with line chart'). This is working on iOS as expected.

On Android if I set setOptions('options with pie chart') a second setOptions call with another chart type does not have any effect. Seems like the chart is not cleanly reset.

@shiv19 : Do you have an idea how I can force to reset the chart. On IOS I am using a single ui-charts view instance to display different chart types which can be selected. On Android currently I can only display a certain chart the very first time and then update its data via updateOptions().

shiv19 commented 3 years ago

@cjohn001 You can only use setOptions once per chart load, after that please use updateOptions https://github.com/NativeScript/nativescript-ui-charts/blob/8756f35e8ca75bafef0be7b3fa068d8fe01dc36d/src/ui-charts.android.ts#L79

cjohn001 commented 3 years ago

@shiv19 : If I set a pie chart with setOptions at the first time. It is not possible to use updateOptions to set for example a line chart with updateOptions afterwords.

On IOS using setOptions multiple times works fine. Is there no way to reset the chart on Android, in order to being able to use setOptions again? I think this should be the standard way how setOptions should work on Android

shiv19 commented 3 years ago

No way that I'm aware of as of now :/

cjohn001 commented 3 years ago

So now way to reuse the same instance for different chart types?

cjohn001 commented 3 years ago

Do you now how I could recreate the native chart view from nativescript code behind? Currently I have a UIChartsView in an Angular template. I assume this could then simulate the behavior? But I do not know how I could do it.

shiv19 commented 3 years ago

If you are on Angular, you can just use *ngIf, since it can completely destroy and re-create a view it won't tax the performance much

cjohn001 commented 3 years ago

so you mean putting lets say 5 charts, one for each type, and display the one to show via *ngIf? So not reusing the existing view? No other option? This would mean I need to redesign a lot of code. :(

Or you mean something like toggling the view when using setOptions? i.e.

<UIChartsView *ngIf="show" />

in code: show = false; show = true; setOptions()

shiv19 commented 3 years ago

I initially thought of putting 5 charts like you said,

but toggling the view is the better idea! Clever thinking there! That should do the trick on Angular.

cjohn001 commented 3 years ago

I just found this comment

https://www.highcharts.com/forum/viewtopic.php?f=9&t=42841


HIOptions options2 = new HIOptions(); options2.setSeries(series3); chartView2.setOptions(options2); // Update Highcharts graph --- Chart fails to update }

But after I run the code and press the button, my chart does NOT update with the new data point despite calling setSeries. Any idea what I'm doing wrong here?

I tried adding the following line of code at the very bottom of the above routine: chartView2.reload(); // Reloads Highcharts graph --- ENTIRE GRAPH IS REDRAWN

Have you tried using reload() in setOptions in the plugin? Maybe that way we could get setOptions working multiple times?

shiv19 commented 3 years ago

I have played around with reload before, can you try adding reload to setOptions just in your node_modules/@nativescript/ui-charts/ui-charts.android.js and let me know if it works?

cjohn001 commented 3 years ago

I will try tomorrow. Quite late already. I have seen that reload is deprecated. Might be that the correct way is calling destroy before calling setOptions. I will try to play around with the API tomorrow. Thanks for your help!

https://api.highcharts.com/android/highcharts/com/highsoft/highcharts/core/HIChartView.html#destroy--

cjohn001 commented 3 years ago

closed with #27