VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-create-group-barchart-in-android/

⇱ How to Create Group BarChart in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create Group BarChart in Android?

Last Updated : 23 Jul, 2025

As we have seen how we can create a beautiful bar chart in Android but what if we have to represent data in the form of groups in our bar chart. So that we can plot a group of data in our bar chart. So we will be creating a Group Bar Chart in our Android app in this article. 

What we are going to build in this article? 

We will be building a simple application in which we will be displaying a bar chart with multiple sets of data in our Android application. We will display the data in the form of the group in our bar chart. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java and Kotlin language.

👁 Bar_Chart


Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note that select Java/Kotlin as the programming language.


Step 2: Add dependency and JitPack Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects{  repositories   ...    maven { url "https://jitpack.io/" }     }}

After adding this dependency sync your project and now we will move towards its implementation.  


Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 

activity_main.xml:

Design UI:

👁 BarChart



Step 4: Working with theMainActivity.java file

Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.

MainActivity File:


Now run your app and see the output of the app.

Explanation/Summary of the above Program are mentioned below:

  • Bar Chart Creation: Uses MPAndroidChart to create a bar chart with two datasets.
  • Data Setup: Defines two sets of data (days of the week with corresponding values).
  • Styling: Customizes bar colors (green and blue) and sets value text size.
  • X-Axis Configuration: Displays day names on the x-axis with labels at the bottom.
  • Interactivity & Animation: Enables drag, adjusts bar spacing, and animates the chart.

Output:


Comment

Explore