Scarlet
Scarlet

Reputation: 11

Android MPAndroidCharts

I'm trying to create my CustomMarkerView class. But when I override the refreshContent, it shows that method does not override from its superclass and that "highlight" parameter is never used.

CustomMarkerView.java sample code

public class CustomMarkerView extends MarkerView {

    private TextView tvContent;
    public CustomMarkerView (Context context, int layoutResource) {
        super(context, layoutResource);
        // this markerview only displays a textview
        tvContent = (TextView) findViewById(R.id.tvContent);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry entries, Highlight highlight) {
        tvContent.setText("" + entries.getVal());
        // set the entry-value as the display text
    }


    @Override
    public int getXOffset() {
        // this will center the marker-view horizontally
        return -(getWidth() / 2);
    }

    @Override
    public int getYOffset() {
        // this will cause the marker-view to be above the selected value
        return -getHeight();
    }
}

I've directly coped the code from

https://github.com/PhilJay/MPAndroidChart/wiki/MarkerView

What am I missing?

Upvotes: 1

Views: 274

Answers (1)

Sijan Gurung
Sijan Gurung

Reputation: 797

Hei,Just checked you code. and if you update your MPAndroidChart version to

compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'

and use the code below ( made changes in your code), Seems to work fine on my side...

public class CustomMarkerView extends MarkerView {

    private TextView tvContent;
    public CustomMarkerView (Context context, int layoutResource) {
        super(context, layoutResource);
        // this markerview only displays a textview
        tvContent = (TextView) findViewById(R.id.tvContent);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry entries, Highlight highlight) {
        tvContent.setText(" " + entries.getVal());
        // set the entry-value as the display text
    }

    @Override
    public int getXOffset(float xpos) {
        return -(getWidth()/2);
    }

    @Override
    public int getYOffset(float ypos) {
        return -getHeight();
    }
}

Upvotes: 1

Related Questions