Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pie chart is flickering whenever new data is inserted #259

Open
zaidnaseer opened this issue Sep 1, 2022 · 1 comment
Open

Pie chart is flickering whenever new data is inserted #259

zaidnaseer opened this issue Sep 1, 2022 · 1 comment

Comments

@zaidnaseer
Copy link

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);
        });
@TarushGupta23
Copy link

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);
        
     
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants