Drawing Chart easily with AchartEngine in Android

 
    Android AChartEngine Library is a free library which can be used to display graphs/charts on any Android OS based devices. AChartEngine supports many chart types like: Line Chart, Area Chart, Scatter Chart, Time Chart, Bar Chart, Pie Chart, Bubble Chart,...One of the most intriguing feature of Android AChartEngine is that it can combine all these charts into a single chart and can use multiple data series.
    This is most popular chart library today. In this post, I will preset how to use it to draw a bar chart, other types are similar.

Start Android Studio and Create a new project.

1. Download and import library

- Download lastest jar file from it's project in Google code.
- Import downloaded file to your project (See this tip for learning how to import external jar library to Android Studio Project).

2. Make a layout (xml) for Activity

Create a simple layout like this:


3. Code code

In our activity, after click button, a bar chart is created. createChart() method:
As you can see:
- From line 6 to line 20: set features for each bar/column of chart and add to Chart Dataset.
- From line 22 to line 99: set features for chart and add all "column dataset".
- From line 100 to line 114: add Chart View to a container layout (LinearLayout).

Full ChartActivity.java code:
Output will be like this:
pic name pic name

Share


Previous post
« Prev Post
Next post
Next Post »