8

I am using a chart library called MPAndroidChart and I am very pleased with it. However, I want to draw a thick vertical line (as a background, not as data) serving as an indicator in the the middle of the line graph. How can I do this?

Best regards.

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Moonlit
  • 5,171
  • 14
  • 57
  • 95

2 Answers2

10

You can use the LimitLine class to acheive this.

Basically, that class allows you to draw a customizeable line to a specified position on the y-axis in the chart and add a description to it.

After creating the line, you need to assign it to an XAxis or YAxis.

For more details, have a look at the documentation. You can find limitlines it on the bottom of the page.

Also, this example class shows how to use them: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java

UPDATE: Now LimitLines can be assigned to any axis!

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • Thank you, this will create a horizontal line at the specified y position. What I want is an vertical line at the middle (graphwidth/2) of the graph, but limit lines cannot be assigned to an x-axis. – Moonlit Mar 12 '15 at 16:05
  • Sorry, I misread. What you described is not possible with limit lines then. You will have to modify the library itself to achieve this. I will consider adding vertical lines in a future update! – Philipp Jahoda Mar 12 '15 at 16:24
  • Did vertical lines ever get added? I see that sometimes when I touch the graph a verticle line is drawn. Can I hook in to that? – bhspencer Mar 22 '15 at 21:41
0

You can draw verctical lines on your graphic using Highlight class. See https://stackoverflow.com/a/42852833/4361772

Community
  • 1
  • 1