PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.56k stars 9.01k forks source link

Dynamic Data and lazy loading in CombinedChart #2539

Open LukasJue opened 7 years ago

LukasJue commented 7 years ago

I'm using an Combined Chart to display data, that I get from a sqlite cursor. The CombinedData contains LineData and BarData, which get updated independently. When shown the first time the current day is visible, but there are at least 3 days (to the past) loaded. When the user scrolls to the left or zooms out (to see historic data) and is nearly to reach the left bound of the loaded data, a trigger loads new data from the sqlite database with lazy loading. When I now apply the new data, the chart changes completely and wants to show to whole data, but I don't want the user to see, that the data is loaded lazy. So when i call combinedData.setData(lineData); mChart.setData(combinedData); I want the chart to stay at the current zoom and x-axis value. Is this possible? When yes how? Is there a way to set the zoom and x-value to the left side of the chart to the old value (before applying the new data), after I applied the new data? Is the a way of apllying data, so that the all stays the same, and only the buffers of the DataSets are extended?

ivnsch commented 7 years ago

I have a situation that seems to require similar functionality: I have a real time line chart where some lines usually have their own "ranges" along the y-axis. So they have some space between them and rarely overlap. The user can select which line to focus on. For this I set the visible y range to the current min and max of this line, using setAxisMinimum and setAxisMaximim. I also have an option to "focus all the lines", for which I simply call setAutoScaleMinMaxEnabled(true). Then the chart resets the y-range and shows all the lines again.

Works well, the problem is that when the chart is focused on one line the users want to be able to pan past the boundaries, so they can see other lines, wihout having to set the chart back to "focus all" mode, which resets the range of the axis.

So basically what I need is:

When a line is focused (i.e. y-axis is constrained to max/min of this line with setAxisMinimum and setAxisMaximim) and user starts panning, stop constraining the range (by not calling setAxisMinimum and setAxisMaximum anymore - it's easy to do this using the gesture listener) and simply allow user to pan past the current boundaries. I'm not seeing right now a way to achieve this. It's similar to if chart was zoomed, except that it's not zoomed, in the sense of "scaled", but the range of the y-axis modified. I could try to implement the "focus on line" functionality using zooming, by calculating the pivot and zoom level needed on each added point to emulate setAxisMinimum and setAxisMaximim, which would allow the user to pan as the chart is only scaled, but this seems a bit painful way to do this and I'm not completely sure yet that it works. I hope there's a better way? Thanks!