0

I've seen this and i want the same lines in my legend as in the Image shown.

Demo

I can't find this in GraphView.getLegendRenderer() Object.

Original Post

1 Answers1

1

for this you have a create your own legend renderer.

Create a new class that extends the LegendRenderer. There you can override the draw method. About line 192 is the part where the rectangle is rendered. Just alter the original code in order to have a line instead of a rect.

https://github.com/jjoe64/GraphView/blob/master/src/main/java/com/jjoe64/graphview/LegendRenderer.java#L192

If you want you can create a pull request or just copy your custom Renderer into a issue at github, then I maybe can merge it into the main for the next release.

Have fun!

appsthatmatter
  • 6,347
  • 3
  • 36
  • 40
  • I have tried to override the method but I couldn't manage it. My overritten method is never called... My idea was to halve the size of `legendHight`. – Luis Garcia Dec 22 '16 at 10:05
  • did you called graph.setLegendRenderer(yourCustomRenderer) ? – appsthatmatter Dec 23 '16 at 10:24
  • Uhm oh no.. I called 'CustomLegend cl = new CustomLegend(); cl.getLegendRenderer()...' – Luis Garcia Dec 28 '16 at 09:37
  • 1
    In case anyone stumbles on this answer years later like me, this isn't viable. LegendRenderer is effectively final because all important fields are private. Extending the class would require making new fields and reinitializing them in addition to calling methods of the original class which is poor practice. Writing a new CustomRenderer which doesn't extend LegendRenderer doesn't work because the setter on GraphView only accepts LegendRenderer. – Aleksandar Malovic Nov 02 '21 at 09:07