MPAndroidChart
MPAndroidChart copied to clipboard
horizontal stacked bar
It works fine at the first time, when i move android page and back again the page then it not working. details in video .
issue details : https://youtube.com/shorts/TDljuv8iVBc?feature=share
Code: private fun chartView(dataList: List<ExpenseCategoryTable>) { "logCate".logDebug("RABBI---->") val titleList = arrayListOf<String>() val item = arrayListOf<Float>() val colorList = arrayListOf<Int>() val entries: MutableList<LegendEntry> = ArrayList()
dataList.onEach {
titleList.add(it.name ?: "")
item.add(it.total_expense?.toFloat() ?: 1f)
colorList.add(Color.parseColor(it.primary_color))
}
val entries1 = arrayListOf(BarEntry(0f, item.toFloatArray()))
val dataSet1 = BarDataSet(entries1, "")
dataSet1.colors = colorList
for (i in dataList.indices) {
val entry = LegendEntry()
entry.formColor = colorList[i]
entry.label = titleList[i]
entries.add(entry)
}
dataSet1.setDrawValues(false)
val barData = BarData(dataSet1)
barData.barWidth = 5f
with(binding.barChart) {
data = barData
description.isEnabled = false
axisRight.isEnabled = false
isHighlightPerTapEnabled = false
legend.isEnabled = true
legend.orientation = Legend.LegendOrientation.HORIZONTAL
legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER
legend.textSize = 14f
legend.isWordWrapEnabled = true
legend.setCustom(entries)
xAxis.axisMinimum = 0f
axisLeft.axisMinimum = 0f
axisRight.mAxisMaximum = 0f
xAxis.setDrawGridLines(false)
xAxis.isEnabled = false
xAxis.mAxisMaximum = 1f
setVisibleXRangeMaximum(5f)
setTouchEnabled(false)
setPinchZoom(false)
isDoubleTapToZoomEnabled = false
axisLeft.isEnabled = false
invalidate()
}
}