AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.
2.32k
stars
369
forks
source link
Vertical Bar data does not refresh when tried to update with new data set. #265
I am using a function and calling it as per year-wise data. Whenever the user changes year new data comes to this function. But the Vertical Bar chart shows the data which is loaded for the very first time. When a different year is selected the animation takes place and loads data that was previously there.
But the debugger shows the updated data in this function.
`private fun setUpBarChart(position: Int) {
val vertical: Cartesian = AnyChart.vertical()
val year = viewModel.graphDataV2.value?.yearlyReport?.get(position)?.year
vertical.removeAllSeries()
vertical.animation(true).title("The tickets closed in year $year")
val data: ArrayList<DataEntry> = ArrayList()
try {
for (month in viewModel.graphDataV2.value?.yearlyReport?.get(position)?.months!!) {
data.add(CustomDataEntry(month.month, month.count, null))
}
} catch (e: Exception) {
Log.d("Parsing Month list ", e.localizedMessage)
}
val set = Set.instantiate()
set.data(data)
val barData: Mapping = set.mapAs("{ x: 'x', value: 'value' }")
val jumpLineData: Mapping = set.mapAs("{ x: 'x', value: 'jumpLine' }")
val bar: Bar = vertical.bar(barData)
bar.labels().format("{%Value}")
val jumpLine: JumpLine = vertical.jumpLine(jumpLineData)
jumpLine.stroke("2 #60727B")
jumpLine.labels().enabled(false)
vertical.yScale().minimum(0.0)
vertical.labels(true)
vertical.tooltip()
.displayMode(TooltipDisplayMode.UNION)
.positionMode(TooltipPositionMode.POINT)
.unionFormat(
"""function() {
return 'Target: ' + this.points[1].value +
'\n' + 'Actual:' + this.points[0].value;
}"""
)
vertical.interactivity().hoverMode(HoverMode.BY_X)
vertical.xAxis(true)
vertical.yAxis(true)
vertical.yAxis(0).labels().format("{%Value}")
anyChartView.setChart(vertical)
}`
Please let me know if am doing anything wrong.
I am using a function and calling it as per year-wise data. Whenever the user changes year new data comes to this function. But the Vertical Bar chart shows the data which is loaded for the very first time. When a different year is selected the animation takes place and loads data that was previously there.
But the debugger shows the updated data in this function.