Menu

Create pie chart graph view

Perform the following steps to create a pie chart graph view.

1. Create category series as follows, which accepts label, proportional share, and so on.

  • Create the instance of CategorySeries.
  • Add the label, proportional share for different labels for which user wants to construct the pie chart.
CategorySeries categorySeries = new CategorySeries("Vehicles Chart");
categorySeries.add("B2B-PLATFORM", 30 , "10");
categorySeries.add("B2B-HEALTHCARE", 20 , "5");
categorySeries.add("B2B-EDUCATION ", 60 , "8");
categorySeries.add("B2B-CLIENT ", 100 , "18");
categorySeries.add("B2B-SERVER" , 75 , "20");

2. Create default renderer (main renderer) for the entire graph as follows.

  • Create the series renderer for the color of different sections which will be added to the main renderer.
  • Using the instance of DefaultRenderer, configure the style. Refer the EDU SDK Javadoc for different style configuration.
DefaultRenderer renderer = new DefaultRenderer();

SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);

renderer.setLabelsColor(Color.BLACK);
renderer.setLabelsTextSize(20);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(BACK_GROUNDCOLOR);
renderer.setDisplaySectorLabel(true);
renderer.setInScroll(true);

3. Use the chart factory method to create the combined chart view.

View pieChartView = ChartFactory.getPieChartView(getActivity(), categorySeries, renderer);

4. Add the returned graph view to your app’s view group for display.

Output