问题
I am using the MPAndroidChart library.
I have multiple scattercharts in a ListView. Every chart contains 365 xvalues (every day of the year). The yvalues vary from 1 to 5. The height of the charts is 150dp. I would like to be able to zoom in, so I can see every single day. But when I zoom in, the yvalues get out of range of the chart. Is there a way to keep the yvalues within range of the chart? I tried it with the next settings:
holder.chart.setTouchEnabled(true);
holder.chart.setDragEnabled(true);
holder.chart.setScaleEnabled(false);
holder.chart.setScaleMinima(3f, 0f);
holder.chart.centerViewPort(xIndex, 3);
But when I drag from left to right or right to left, values just disappear from the chart, even when in range.
Has anyone any idea how to accomplish this?
回答1:
This is your issue:
holder.chart.setScaleMinima(3f, 0f);
You are setting the scale value of the y-axis to zero. By doing that, you practically zoom out the chart into infinity. If you do not want to manipulate the zoom/scale of the y-axis, set the y-scale to 1f. Like this:
holder.chart.setScaleMinima(3f, 1f);
回答2:
Try to invalidate the chart after centerViewPort, worked for me.
holder.chart.invalidate();
来源:https://stackoverflow.com/questions/26955668/mpandroidchart-scatterchart-in-listview