Skip to content

Bar Graph

Jonas Gehring edited this page Apr 12, 2019 · 2 revisions

Bar Graph Series in detail

To plot a Bar Diagram with Graph View you have to use the class BarGraphSeries. The bars will have its origin at the zero-line. So if you have negative y-values, the bars will be inverted. It is important that the data you're using is in a regular interval (x) and without holes, because for every data point there will be a single bar. There are some styling options:

  • Values on top

    The y-values of a single bar can be displayed above the bar. You can specify the color and text size. Use barGraphSeries.setDrawValuesOnTop()

  • Value dependent color

    You can implement a hook that let you define the color of the bars in dependence of the y-value. Use barGraphSeries.setValueDependentColor()

  • Spacing

    If you do not want that the bars fill the complete viewport, you can define a spacing between the bars in percentage.

Here is an example with the styling options:

GraphView graph = (GraphView) findViewById(;
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
    new DataPoint(0, -1),
    new DataPoint(1, 5),
    new DataPoint(2, 3),
    new DataPoint(3, 2),
    new DataPoint(4, 6)

// styling
series.setValueDependentColor(new ValueDependentColor<DataPoint>() {
    public int get(DataPoint data) {
    return Color.rgb((int) data.getX()*255/4, (int) Math.abs(data.getY()*255/6), 100);


// draw values on top


You can’t perform that action at this time.