选择值时显示标签[MPAndroidChart]

时间:2017-04-18 08:24:12

标签: android mpandroidchart

我想在选择一个值时显示一个带有特定数据的标签,就像我想要的演示图像一样:

Image of the I want

所以我粘贴这段代码(在例子的来源中找到):

protected RectF mOnValueSelectedRectF = new RectF();

@Override
public void onValueSelected(Entry e, Highlight h) {

    if (e == null)
        return;

    RectF bounds = mOnValueSelectedRectF;
    mChart.getBarBounds((BarEntry) e, bounds);
    MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);

    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());

    Log.i("x-index",
            "low: " + mChart.getLowestVisibleX() + ", high: "
                    + mChart.getHighestVisibleX());

    MPPointF.recycleInstance(position);
}

但它不起作用,显示日志但屏幕上没有任何内容。 我忘了或错过了什么

2 个答案:

答案 0 :(得分:2)

要在选择值时显示带有内容的标记,我们必须使用MarkerView而不是valueSelected侦听器。

创建你的所有必要文件都在这里: https://github.com/PhilJay/MPAndroidChart/wiki/IMarker-Interface

答案 1 :(得分:0)

您是否在代码中的行下方写过?

mChart.setOnChartValueSelectedListener(this);