Android Simple Bar Chart Tutorial

Displaying the analysis data using the list of text in the application is very confusing to the user. How can we make our data displaying with more user-friendly?  We can display all the data by graphical representation to minimize and summarizes the complexity of data. It is the visual display of data using plots and charts. It is used in many academic and professional disciplines but most widely so in the fields of mathematics, medicine, and the sciences. In this tutorial, I will tell you on how to create an android simple bar chart in the new project.

Sample Screenshot

sample screenshot android simple barchart

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “BarChartExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add a new dependency

In your module gradle file add a new dependency “MPAndroidChart”. I use this library for creating a bar chart on android.

Create a new class

Right click the package name and create a new class “DayAxisValueFormatter” to Formatting Day.

Create another new class

Create a new class “MyAxisValueFormatter” to formatting the currency how its display. It should implement the IAxisValueFortter interface in this class.

Create a new custom MarkerView class

After that, create another new class to custom MarkerView in your chart.

Add a new custom layout for MarkerView

Create a new xml layout in your layout folder and name it “custom_marker_view.xml”. Remember to add an image in your drawable so that you can use that image for your custom marker.

Edit activity_main.xml layout

Go to the activity_main layout and add BarChart inside this layout.

Edit MainActivity.class java

Open this class and it will initialise the bar chart in your activity. You can follow the source code below.

Run Your Project

In conclusion, now you can run this project in your android emulator to check how the bar chart been populated in the activity.

(Android Simple Bar Chart)

Source Code

(Visited 4,596 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

1 Response

  1. Webb Act says:

    Thank you for the post, please how do i display last 3 or six months at the bottom of the chart, like Sep, Oct, Nov, Jan, Feb

Leave a Reply

Your email address will not be published. Required fields are marked *