2

Hello I wan't to know if this kind of graphics are possible using MP Android Chart:

enter image description here

What I really need is to customize the entire XAxis with several other UI Components (In this case 4 TextViews and an ImageView).

I've been trying different solutions like using a RecyclerView with a BarChart inside of it's cell but I am not achieving the efficient UI:

enter image description here

I have also tried to add a ListView below the Chart but I was not able to sync and order the ListView cells according to the Chart.

Any Ideas?

Mario Galván
  • 3,964
  • 6
  • 29
  • 39

1 Answers1

3

The kind of graphics that you have posted in your picture are certainly possible, although not easy, with MPAndroidChart.

You will have to write your own subclass of XAxisRenderer:

ViewPortHandler vph = mChart.getViewPortHandler();
XAxisRenderer xAxisRenderer = new CustomXAxisRenderer(vph, mChart.getXAxis(), vph.getTransformer(AxisDependency.LEFT), image);
mChart.setXAxisRenderer(new CustomXAxisRenderer());

A very simple proof-of-concept would look something like this:

public class CustomXAxisRenderer extends XAxisRenderer {

    Bitmap image;

    public CustomXAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer transformer, Bitmap image) {
        super(viewPortHandler, xAxis, transformer);
        this.image = image;
    }

    @Override
    protected void drawLabels(Canvas c, float pos, MPPointF anchor) {
        //same code as super class
        //then, code to draw the bitmap image on the canvas
        //and, code to draw the extra text
    }
}

Please see the following answers for how to scale bitmap images and draw them on the canvas:

How to make a custom image inside bars in MPAndroidChart

How to make a custom highlight drawable in MPAndroidChart

When you have a complete solution you are welcome to post it here as an answer. Good luck!

Note for proof of concept: overriding drawLabels is a little crude. A better solution would extract a separate method from drawLabels and make sure it is called in the draw(Canvas c) of the superclass. See this answer if you want to do that.

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