Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a long red line (limit line) in MPAndroidChart

I am using MPAndroidChart library version 2.2.4. My requirement is I want to set three marker lines in a BarChart with values "Minimum", "Average" and "Maximum" like in the image below, but I can't find any solution for this.

a line chart with three red limit lines labelled max, average, and min

like image 846
Neha Shukla Avatar asked Jan 18 '17 10:01

Neha Shukla


1 Answers

In MPAndroidChart 3.x.x what you are asking for is called a LimitLine

There is an example of how to consume it in the sample project:

    LimitLine ll1 = new LimitLine(150f, "Upper Limit");
    ll1.setLineWidth(4f);
    ll1.enableDashedLine(10f, 10f, 0f);
    ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
    ll1.setTextSize(10f);
    ll1.setTypeface(tf);


    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
    leftAxis.addLimitLine(ll1);

If you require a customized limit line, you will have to look at the instructions in this question here

like image 123
David Rawson Avatar answered Nov 02 '22 05:11

David Rawson