|
|
@@ -1,8 +1,6 @@
|
|
|
package com.yingyang.workbenches.brainability
|
|
|
|
|
|
-import android.graphics.Color
|
|
|
import android.graphics.Typeface
|
|
|
-import android.text.TextUtils
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.github.mikephil.charting.components.XAxis
|
|
|
@@ -10,6 +8,7 @@ import com.github.mikephil.charting.components.YAxis
|
|
|
import com.github.mikephil.charting.data.Entry
|
|
|
import com.github.mikephil.charting.data.LineData
|
|
|
import com.github.mikephil.charting.data.LineDataSet
|
|
|
+import com.github.mikephil.charting.formatter.ValueFormatter
|
|
|
import com.yingyang.workbenches.R
|
|
|
import com.yingyang.workbenches.adapter.BrainAbilityTypeAdapter
|
|
|
import com.yingyang.workbenches.databinding.FragmentBrainAbilityBinding
|
|
|
@@ -82,12 +81,25 @@ class BrainAbilityFragment :
|
|
|
}
|
|
|
}
|
|
|
binding.lineChart.data = lineData
|
|
|
+ val xAxis: XAxis = binding.lineChart.xAxis
|
|
|
+ if (xType.isEmpty().not()) {
|
|
|
+ setAXisData(xAxis)
|
|
|
+ }
|
|
|
binding.lineChart.invalidate()
|
|
|
}
|
|
|
adapter.setData(variationTendencyByTypeBean)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ private fun setAXisData(xAxis: XAxis) {
|
|
|
+ val valueFormatter = object : ValueFormatter() {
|
|
|
+ override fun getFormattedValue(value: Float): String {
|
|
|
+ return xType[value.toInt() % xType.size]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xAxis.valueFormatter = valueFormatter
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设置线条颜色
|
|
|
*/
|
|
|
@@ -122,6 +134,13 @@ class BrainAbilityFragment :
|
|
|
binding.lineChart.description = null
|
|
|
//Y 自下往上动态绘制 这里添加初始的动画效果
|
|
|
binding.lineChart.animateY(1000)
|
|
|
+ binding.lineChart.setTouchEnabled(true)
|
|
|
+ binding.lineChart.setScaleEnabled(false)
|
|
|
+ binding.lineChart.setPinchZoom(true)
|
|
|
+ binding.lineChart.isDragEnabled = true
|
|
|
+ binding.lineChart.extraBottomOffset = 20f
|
|
|
+ binding.lineChart.extraRightOffset = 30f
|
|
|
+ binding.lineChart.extraLeftOffset = 10f//间距
|
|
|
//获取柱状图的X轴
|
|
|
val xAxis: XAxis = binding.lineChart.xAxis
|
|
|
//下面两个是获取Y轴 包括左右
|
|
|
@@ -146,7 +165,7 @@ class BrainAbilityFragment :
|
|
|
//设置X轴显示
|
|
|
axis.isEnabled = true
|
|
|
axis.textColor = resources.getColor(R.color.color_FF222222)
|
|
|
- axis.textSize = resources.getDimension(R.dimen.divider_20px)
|
|
|
+ axis.textSize = 12f
|
|
|
axis.setLabelCount(7, true)
|
|
|
//y轴0刻度
|
|
|
axisLeft.axisMinimum = 0f
|