package com.casic.smarttube.extensions import com.casic.smarttube.R import com.github.mikephil.charting.animation.Easing import com.github.mikephil.charting.charts.Chart import com.github.mikephil.charting.charts.LineChart import com.github.mikephil.charting.components.XAxis import com.github.mikephil.charting.components.YAxis import com.pengxh.kt.lite.extensions.dp2px fun LineChart.initConfig() { this.setNoDataText("无数据,无法渲染...") this.setNoDataTextColor(R.color.orangeTextColor) this.getPaint(Chart.PAINT_INFO).textSize = 12f.dp2px(this.context) this.setDrawGridBackground(false) this.setDrawBorders(false) this.isScaleXEnabled = true //X轴可缩放 this.isScaleYEnabled = false //Y轴不可缩放 this.isDragEnabled = true this.description.isEnabled = false this.extraBottomOffset = 5f //底部边距 //去掉图例 this.legend.isEnabled = false this.animateY(1200, Easing.EaseInOutQuad) //设置样式 val rightAxis: YAxis = this.axisRight //设置图表右边的y轴禁用 rightAxis.isEnabled = false val leftAxis: YAxis = this.axisLeft leftAxis.axisMinimum = 0f leftAxis.axisMaximum = 100f //设置x轴 val xAxis: XAxis = this.xAxis xAxis.textSize = 10f xAxis.setDrawLabels(true) //绘制标签 指x轴上的对应数值 xAxis.setDrawAxisLine(true) //是否绘制轴线 xAxis.setDrawGridLines(false) //设置x轴上每个点对应的线 xAxis.granularity = 1f //禁止放大后x轴标签重绘 xAxis.position = XAxis.XAxisPosition.BOTTOM xAxis.labelRotationAngle = -45f }