Skip to content

Multiple charts in a single layout

ArsenyMalkov edited this page Oct 3, 2018 · 4 revisions

After adding AnyChartViews in your layout, you should find and set as active particular AnyChartView for which a chart should be created.

AnyChartView anyChartView = findViewById(R.id.any_chart_view);
APIlib.getInstance().setActiveAnyChartView(anyChartView);

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

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

anyChartView.setChart(pie);

After you have done all manipulations with the first chart, you should do exactly the same thing for the next one. Find AnyChartView and set it active.

AnyChartView anyChartView1 = findViewById(R.id.any_chart_view1);
APIlib.getInstance().setActiveAnyChartView(anyChartView1);

Pie pie1 = AnyChart.pie();

List<DataEntry> data1 = new ArrayList<>();
data1.add(new ValueDataEntry("Apples", 6371664));
data1.add(new ValueDataEntry("Pears", 789622));
data1.add(new ValueDataEntry("Bananas", 7216301));
data1.add(new ValueDataEntry("Grapes", 1486621));
data1.add(new ValueDataEntry("Oranges", 1200000));

pie1.data(data1);

anyChartView1.setChart(pie1);

If you need to change chart data after charts was rendered, first of all, you should set its AnyChartView active and then apply new data.

APIlib.getInstance().setActiveAnyChartView(anyChartView);
pie.title("First chart");
APIlib.getInstance().setActiveAnyChartView(anyChartView1);
pie1.title("Second chart");
Clone this wiki locally