MPAndroidChart - 常用属性

一、常用属性

参考地址:https://blog.csdn.net/qq_25943493/article/details/51803497
中文文档:https://github.com/baiqingsong/ChartDawn

// 禁止触摸/拖动/缩放
bc.setTouchEnabled(false)
bc.isDragEnabled = false
bc.setScaleEnabled(false)
//不绘制网格背景
bc.setDrawGridBackground(false)
// 处理y坐标轴
bc.axisRight.isEnabled = false // 右侧不显示Y轴
bc.axisLeft.axisMinimum = 0f //设置Y轴显示最小值,不然0下面会有空隙
bc.axisLeft.setDrawGridLines(false) //不设置Y轴水平线显示
bc.axisLeft.axisLineColor = Color.TRANSPARENT // 设置左侧y轴坐标轴线的颜色

// 处理x坐标轴
bc.xAxis.position = XAxis.XAxisPosition.BOTTOM // 设置坐标轴位置
bc.xAxis.setDrawGridLines(false) // 设置X轴竖直线的显示
// 显示每一个 X 轴的数值,第一个参数为x轴数值个数,第二个是否强制使用坐标轴数值
bc.xAxis.setLabelCount(10, false)

// 设置偏移量
bc.extraBottomOffset = 14f // 底部偏移量

// 设置描述
bc.description = Description().apply {
text = "min"
setPosition(30.toPx().toFloat(), 25.toPx().toFloat()) // 修改显示的位置
textAlign = Paint.Align.LEFT // 显示在左边/右边/中间
}

// 处理标签
val legend = bc.legend
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER // 设置标签横向居中
legend.verticalAlignment = Legend.LegendVerticalAlignment.TOP // 设置标签在顶部
//背景阴影
bc.setDrawBarShadow(false)
bc.isHighlightFullBarEnabled = false
//显示边界
bc.setDrawBorders(false)
bc.setPadding(1, 1, 1, 1)
// 设置描述
bc.description = Description().apply {
text = ""
}
阅读更多