建议更换setStartAtZero弃用方法不起作用

时间:2017-12-14 13:53:00

标签: android mpandroidchart

我有以下代码用于显示工作正常的烛台图表(图表开始使用框架中的最小/最大Y值进行缩放):

    CandleDataSet dataset = new CandleDataSet(entries, "");

    dataset.setDecreasingColor(Color.RED);
    dataset.setIncreasingColor(Color.GREEN);
    dataset.setDecreasingPaintStyle(Paint.Style.FILL);

    CandleData data = new CandleData(labels, dataset);

    candleStickChart.getAxisLeft().setStartAtZero(false); //Deprecated
    candleStickChart.setData(data);

    candleStickChart.setDescription("Candlestick Chart");
    candleStickChart.animateY(1000);

然而 - 根据the docs

setStartAtZero(boolean enabled): Deprecated - Use setAxisMinValue(...) or setAxisMaxValue(...) instead.

我已将我的代码更改为以下内容但它似乎不起作用(图表以帧中的Y值0开头,当最小值从13000开始时无用):

    CandleDataSet dataset = new CandleDataSet(entries,"");

    dataset.setDecreasingColor(Color.RED);
    dataset.setIncreasingColor(Color.GREEN);
    dataset.setDecreasingPaintStyle(Paint.Style.FILL);

    CandleData data = new CandleData(labels, dataset);

    candleStickChart.getAxisLeft().setAxisMinValue(data.getYMin()); //New Code
    candleStickChart.invalidate();
    candleStickChart.setData(data);

    candleStickChart.setDescription("Candlestick Chart");
    candleStickChart.animateY(1000);

1 个答案:

答案 0 :(得分:0)

而不是:

candleStickChart.getAxisLeft().setAxisMinValue(data.getYMin());

尝试:

candleStickChart.getAxisLeft().setAxisMinimum(dataSet.getYMin());