1

Currently, each bar's domain label appears below the left hand side of each bar, as pictured here:

enter image description here

Is there a way to position labels below each bar's center ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
matdev
  • 4,115
  • 6
  • 35
  • 56
  • It wouldn't make sense at all (to me, at least). Each label should indicate which bar it belongs to by being positioned exactly under it. – Phantômaxx Mar 06 '18 at 13:30
  • It depends what you mean by "exactly under it", but to me they should be under it of course, but between each bar's edge, not below the left edge – matdev Mar 06 '18 at 13:48
  • 1
    If I got you well, you mean "each one centered to the corresponding bar width". Maybe you'll have to take the source of the library and make your own implementation. I did some modifications to aChartEngine - not only to make it slimmer, but also to fit my needs. – Phantômaxx Mar 06 '18 at 14:57

2 Answers2

1

This should do the trick:

XYGraphWidget.LineLabelStyle style = plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM);
style.getPaint().setTextAlign(Paint.Align.CENTER);
Nick
  • 8,181
  • 4
  • 38
  • 63
0

I believe you are doing that on canvas.

  1. You already know the width of the bar.
  2. Measure the text size (width) to be displayed using Measuring text height to be drawn on Canvas ( Android )
  3. (barWidth/2 - textWidth/2) + barLeft should do, i think.
Sivakumar S
  • 681
  • 5
  • 19