Skip to content

Commit

Permalink
Fix empty bar chart issue
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed Apr 18, 2024
1 parent 921ce21 commit a2e569d
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class BarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
val dataSet = if (hasData) {
buildDataSet(context, mappedEntries)
} else {
BarDataSet(emptyList(), "Empty")
buildEmptyDataSet(cutEntries.size)
}
item.onBarChartDrawn?.invoke(dataSet.entryCount)
val dataSets = mutableListOf<IBarDataSet>()
Expand Down Expand Up @@ -208,6 +208,11 @@ class BarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
}
}

private fun buildEmptyDataSet(count: Int): BarDataSet {
val emptyValues = (0 until count).map { index -> BarEntry(index.toFloat(), 0f, "empty") }
return BarDataSet(emptyValues, "Empty").apply { setDrawValues(false) }
}

private fun buildDataSet(context: Context, cut: List<BarEntry>): BarDataSet {
val dataSet = BarDataSet(cut, "Data")
chart.renderer.paintRender.shader = null
Expand Down

0 comments on commit a2e569d

Please sign in to comment.