Android Chart Example - Android

How to create chart in android?

Snippet Code

Rate this page :
  [ 0 votes]

MPAndroidChart library is a simple and easy technique which is used to create charts like bar,pie etc.. Here,the simple steps to create a bar chart in android for mobile price variation.

Step 1: ------- Download latest version of MPAndroidChart librery. Copy mpandroidchartlibrary-1-7-4.jar to your project's libs directory. In Android Studio, right click the JAR file and select Add as Library. Step 2: ------- Create a Dataset to create Charts like bar,pie,bubble etc.. Step 3: ------- Arraylist entry is used to create such Dataset ArrayList<BarEntry> entries = new ArrayList<>(); entries.add(new BarEntry(4f, 0)); entries.add(new BarEntry(8f, 1)); entries.add(new BarEntry(6f, 2)); entries.add(new BarEntry(12f, 3)); entries.add(new BarEntry(18f, 4)); entries.add(new BarEntry(9f, 5)); Step 4: ------- Then define labels of X-axis: ArrayList<String> labels = new ArrayList<String>(); labels.add("January"); labels.add("February"); labels.add("March"); labels.add("April"); labels.add("May"); labels.add("June"); Step 5: ------- Then,by this code you can crate a bar chart: BarChart chart = new BarChart(context); setContentView(chart); BarChart chart = new BarChart(context); setContentView(chart); chart.setDescription("# of times price variation in mobile price");


Ask Questions

Ask Question