Skip to content

Instantly share code, notes, and snippets.

@ArsenyMalkov
Last active February 21, 2023 17:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArsenyMalkov/4f13aca9bdde09abd6547b2fde5bede6 to your computer and use it in GitHub Desktop.
Save ArsenyMalkov/4f13aca9bdde09abd6547b2fde5bede6 to your computer and use it in GitHub Desktop.
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
final Pie pie = AnyChart.pie();
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("Apples", 6371664));
data.add(new ValueDataEntry("Pears", 789622));
data.add(new ValueDataEntry("Bananas", 7216301));
data.add(new ValueDataEntry("Grapes", 1486621));
data.add(new ValueDataEntry("Oranges", 1200000));
pie.data(data);
anyChartView.setChart(pie);
final int delayMillis = 500;
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
public void run() {
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("Apples", new Random().nextDouble() * 140d));
data.add(new ValueDataEntry("Pears", new Random().nextDouble() * 140d));
pie.data(data);
handler.postDelayed(this, delayMillis);
}
};
handler.postDelayed(runnable, delayMillis);
@AmanGoyal-Oodles
Copy link

Using this code Pie Chart is not showing.

@jvlichai
Copy link

Great! It works. Thanks!

@nikunjparadva
Copy link

can you show for column chart?

@Pranavg387
Copy link

The changes are not applied in the app ?? the data is different but the resultant pie chart is the same. Please Help!
`package com.example.piechart;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.chart.common.dataentry.DataEntry;
import com.anychart.chart.common.listener.Event;
import com.anychart.chart.common.listener.ListenersInterface;
import com.anychart.charts.Pie;
import com.anychart.enums.Align;
import com.anychart.enums.LegendLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AnyChartView anyChartView = findViewById(R.id.any_chart_view);
  

    Pie pie = AnyChart.pie();

    pie.setOnClickListener(new ListenersInterface.OnClickListener(new String[]{"x", "value"}) {
        @Override
        public void onClick(Event event) {
            
        }
    });

    List<DataEntry> data = new ArrayList<>();
   data.add(new ValueDataEntry("Apples", 6));
    data.add(new ValueDataEntry("Pears", 7));
    data.add(new ValueDataEntry("Bananas", 7));
    data.add(new ValueDataEntry("Grapes", 1));
    data.add(new ValueDataEntry("Oranges", 1));

    {pie.data(data);

    pie.title("Fruits imported in 2019 (in kg)");

    pie.labels().position("outside");

    pie.legend().title().enabled(true);
    pie.legend().title()
            .text("Retail channels")
            .padding(0d, 0d, 10d, 0d);

    pie.legend()
            .position("center-bottom")
            .itemsLayout(LegendLayout.HORIZONTAL)
            .align(Align.CENTER);
    System.out.print("here");}

    anyChartView.setChart(pie);
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment