HorizontalBarGraph

Additional

Language
Java
Version
1.1 (Jun 13, 2018)
Created
Jan 17, 2018
Updated
Jul 27, 2023
Owner
Felix Soares (felixsoares)
Contributor
Felix Soares (felixsoares)
1
Activity
Badge
Generate
Download
Source code

Horizontal Bar Graph

Android graph view library

Getting Started

Add it in your root build.gradle (Project module)

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

Add the dependency in build.gradle (App module)

dependencies {
 compile 'com.github.felixsoares:HorizontalBarGraph:1.1'
}

Usage example

In layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <br.com.felix.horizontalbargraph.HorizontalBar
        android:id="@+id/horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

In Activity or Fragment

HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).build();

Documentation

  1. Add itens or single bar item
HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).addAll(itens()).addOne(new BarItem("yyy", 1000d)).build();

or

HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).build();

horizontal.addAll(itens());
horizontal.add(new BarItem("yyy", 1000d));
  1. Support Animation
HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).hasAnimation(true).addAll(itens()).build()
  1. Colors
List<BarItem> items = new ArrayList<>();

//Will generate the bar colors and text colors automatically randomly
items.add(new BarItem("ABC", 250d)); 
items.add(new BarItem("ABCD", 800d, 550d));

//Set colors from bar and text foreground
//                                 bar color, text color
items.add(new BarItem("ABC", 250d, Color.RED, Color.WHITE)); 

//              first bar color, second bar color, first text color, second text color
items.add(new BarItem("Teste " + i, 800d, 600d, Color.RED, Color.GREEN, Color.WHITE, Color.WHITE));
  1. Remove itens
horizontal.removeOne(position);

or

horizontal.removeAll();
  1. Change Locale
HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).addAll(itens()).addOne(new BarItem("yyy", 1000d)).build(new Locale("es", "ES"));

or (device default)

HorizontalBar horizontal = findViewById(R.id.horizontal);
horizontal.init(this).addAll(itens()).addOne(new BarItem("yyy", 1000d)).build();

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.