今天来盘一下图表的视窗显示!
注意:以下方法只适用于LineChart,BarChart,ScatterChart和CandleStickChart
设置可见事物
- setVisibleXRangeMaximum(float maxXRange) —— 设置X轴可见范围的大小,该范围是一次可见的最大值。如果这被设置为10,则不需要滚动就可以同时查看x轴上的10个值。
- setVisibleXRangeMinimum(float minXRange) —— 设置X轴可见范围的大小,该范围是最小可见值。如果这被设置为10,则不可能进一步放大x轴上的10个值。
- setVisibleYRangeMaximum(float maxYRange, AxisDependency axis) —— 设置Y轴可见范围的大小,这是最大的一次可见。第二参数是左边Y轴或者右边Y轴(指的是应用到左边或者右边)。
- setViewPortOffsets(float left, float top, float right, float bottom) —— 为当前视图设置自定义偏移量(实际图表窗口两侧的偏移量)。设置此设置将防止图表自动计算其偏移量。
- resetViewPortOffsets() —— 初始化所有设置的偏移
- setExtraOffsets(float left, float top, float right, float bottom) —— 设置额外的偏移量(围绕图表视图),以附加到自动计算的偏移量.这不会改变自动计算的偏移量,但会增加额外的空间。
移动视图
- fitScreen() —— 重置所有缩放和拖动,并使图表完全适合它的边界(完全放大)。
- moveViewToX(float xValue) —— 将当前视图的左侧(边缘)移动到指定的x值.
- moveViewToY(float yValue, AxisDependency axis) —— 在所提供的y轴(左或右)上将视图设置为指定的y值。
- moveViewTo(float xValue, float yValue, AxisDependency axis) —— 将当前视图的左侧移动到x轴上指定的x值,并在所提供的y轴上将视图设置为指定的y值
- centerViewTo(float xValue, float yValue, AxisDependency axis) —— 将当前视图的中心移动到指定的x值和y值
用动画移动视图
注意:这里所有的方法都会自动刷新图表
- moveViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) —— 使用动画效果将左边缘移至所要到的点
- centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) —— 使用动画效果将中心移至所要到的点
缩放(代码设置的方式)
- zoomIn() —— 以1.4f的缩放比系数放大视图中心焦点
- zoomOut() —— 从视图中心焦点以0.7f的缩放比系数缩小视图
- zoom(float scaleX, float scaleY, float x, float y) —— 自定义缩放比,自定义缩放中心,记住 1f缩放值等于没有缩放 0到1之间为缩小操作,1以上为放大操作
- zoom(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis) —— 和上面的方法一样,增加了指定哪一边的Y轴
缩放动画
zoomAndCenterAnimated(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis, long duration)
—— 使用动画进行具体缩放比的缩放操作
- 本文作者: Android YU
- 本文链接: http://yoursite.com/2020/03/19/MPAndroidChart的详细使用——修改视窗显示/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!