Open zaidnaseer opened 2 years ago
thats because whenever you click the button you start that runnable, why dont you just run it once instead of using runable?
pie = AnyChart.pie();
AnyChartView anyChartView = binding.anyChartView;
anyChartView.setChart(pie);
binding.getPieChartBtn.setOnClickListener(v -> {
// amountForCategory array is retrieved from database whenever button is clicked
List<DataEntry> data = new ArrayList<>();
if(amountForCategory[0]!=0) data.add(new ValueDataEntry("Food", amountForCategory[0]));
if(amountForCategory[1]!=0) data.add(new ValueDataEntry("Transportation", amountForCategory[1]));
if(amountForCategory[2]!=0) data.add(new ValueDataEntry("Rent", amountForCategory[2]));
if(amountForCategory[3]!=0) data.add(new ValueDataEntry("Medicine", amountForCategory[3]));
if(amountForCategory[4]!=0) data.add(new ValueDataEntry("Other", amountForCategory[4]));
pie.data(data);
});
I want to update the pie chart from the data from a local database whenever I press the button, but whenever I press it the chart is flickering with old and new data. Here's my code.