如何在堆叠垂直条形图中使用Markerview?

时间:2019-08-03 06:26:36

标签: android mpandroidchart

我在显示自定义标记示例时遇到问题。当我单击堆积的条形图时,它显示单个条形图的总价值,但我需要显示堆积的条形图

“公共类MyMarkerView扩展了MarkerView {

    private final TextView tvContent;

    public MyMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        tvContent = findViewById(R.id.tvContent);
    }

    // runs every time the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        if (e instanceof CandleEntry) {

            CandleEntry ce = (CandleEntry) e;

            tvContent.setText(Utils.formatNumber(ce.getHigh(), 0, false));
        } else {
            tvContent.setText(Utils.formatNumber(e.getY(), 0, false));
        }

        super.refreshContent(e, highlight);
    }

    private MPPointF mpPointF;

    @Override
    public MPPointF getOffset() {

        if(mpPointF == null){
            mpPointF = new MPPointF(-(getWidth() / 2), -getHeight());
        }
        return mpPointF;
    }

}"

1 个答案:

答案 0 :(得分:0)

就我而言,解决方案是更改:

e.getY()

收件人:

((BarEntry) e).getYVals()[highlight.getStackIndex()]