Skip to content

Pie chart is flickering whenever new data is inserted #259

@zaidnaseer

Description

@zaidnaseer

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.

pie = AnyChart.pie();
AnyChartView anyChartView = binding.anyChartView;
anyChartView.setChart(pie);

binding.getPieChartBtn.setOnClickListener(v -> {
//   amountForCategory array is retrieved from database whenever button is clicked
        final int delayMillis = 500;
        final Handler handler = new Handler();
        final Runnable runnable = new Runnable() {
            public void run() {
                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);
        
        
                handler.postDelayed(this, delayMillis);
            }
        };
        handler.postDelayed(runnable, delayMillis);
        });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions