1

I would like to add some extra labels to a LineChart (MPAndroidChart) like in the image below. Notice the "Advanced", "Novice" etc labels.

enter image description here

How could I add those to specified y-axis positions so they will always show up like y-axis labels but perhaps on the inside of the graph as shown - or on the right side if necessary?

Update:

All I needed to get what I needed was some LimitLines like this:

LimitLine noviceline = new LimitLine( SSGlobals.getWeightinPreferredUnits_fromPounds(standardweightsarr[2]) , getString(R.string.novice));
                        noviceline.setLineColor(ContextCompat.getColor(getActivity(), R.color.accentline));
                        noviceline.setTextColor(ContextCompat.getColor(getActivity(), R.color.accentline));
                        noviceline.setTextSize(12);
                        noviceline.setLineWidth(4);

I might style it up a bit more but so far the result looks like so: enter image description here

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
lost baby
  • 3,178
  • 4
  • 32
  • 53

1 Answers1

1

There are a couple of options here.

You can see if the LimitLines will fit your purpose - they are able to be configured with a label like this:

    LimitLine llXAxis = new LimitLine(10f, "Index 10");
    llXAxis.setLineWidth(4f);
    llXAxis.enableDashedLine(10f, 10f, 0f);
    llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
    llXAxis.setTextSize(10f);
    xAxis.addLimitLine(llXAxis); 

You could also use a FrameLayout with over the chart with TextViews for the extra info you want to add. See this question for something similar and also this question for how to convert between chart values and on-screen pixel co-ordinates.

Alternatively, you can extend the renderer itself to draw your custom text. Please see How do MPAndroidChart renderers work and how do I write a custom renderer? if you wish to attempt that.

David Rawson
  • 20,912
  • 7
  • 88
  • 124