How to force no data label display in case of empty DataSet

2.8k views Asked by At

I need to redraw my charts and sometimes some data sets can be empty.

Using an empty DataSet (in PieChart and BarChart) displays an empty chart instead of the no data labels.

How can I force the label display?

Thank you and great work! I really appreciate your work!

2

There are 2 answers

0
verodigiorgio On BEST ANSWER

Found the solution in the library code.

just call clear function on the chart object

chart.clear();

0
SKUSER93 On

In my case when my charts are empty the y max value is 0 so I solved the issue by defining a boolean variable and I set the data to null if the y max value is indeed 0.

example:

val isChartDataEmpty = chartData.yMax == 0f
...
chart.data = if (!isChartDataEmpty ) chartData else null