After MPAndroidChart LineChart uses LineChart.zoom to zoom in, the head and tail x-axis display is incomplete, and zooming in and out fails

Use this method to set the last page to display 7 fixedly and zoom in according to the ratio
        //设置一页最大显示个数为7,超出部分就滑动
        float ratio = (float) bodyFatScaleDatasList.size()/(float) 7;
        //显示的时候是按照多大的比率缩放显示,1f表示不放大缩小
        mLineChart.zoom(ratio,1f,0,0);
jump to last position
 mLineChart.moveViewToX(lastIndex);

The first one on the x-axis appears incomplete
Line chart effect

This may be just at the edge after scaling up, so it is not displayed.

Try directly to reduce the magnification ratio
        //设置一页最大显示个数为7,超出部分就滑动
        float ratio = (float) bodyFatScaleDatasList.size()/(float) 7-0.01f;
The results show

insert image description here
Now it shows normal

There will be an abnormal display zoom when re-refreshing
/**
         * 先将缩放比设置成0后,再去设置你想要的缩放比。
         * 若不这样做的话,在当前页面重新加载数据时,你所设置的缩放比会失效
         */
        mLineChart.zoom(0,1f,0,0);
        mLineChart.zoom(ratio,1f,0,0);
Summarize

There are many property settings when operating a line chart. When there is a problem with the X-axis when zooming in, there are many different processing methods. You can choose according to your project needs.

Guess you like

Origin blog.csdn.net/weixin_44232136/article/details/115366537