我使用双向搜索栏来选择最小和最大范围。
当最大范围向下时,它起作用,但是当向上拉最小范围时,它会失败。
范围搜索栏OnRangeSekkbarChangedListener
:
RangeSeekBar.OnRangeSeekBarChangeListener<Integer> skListener = new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
int max = bar.getSelectedMaxValue().intValue();
int min = bar.getSelectedMinValue().intValue();
mChart.resetTracking();
//Hold of actual drawing lists
List<CandleEntry> y = new ArrayList<CandleEntry>();
List<String> x = new ArrayList<String>();
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
y.add(current);
x.add(currentDate);
}
//Show less of the chart and invalidate
CandleDataSet mSet = new CandleDataSet(y, "Price");
mSet.setDecreasingColor(getResources().getColor(R.color.black));
mSet.setIncreasingPaintStyle(Paint.Style.FILL);
mSet.setIncreasingColor(getResources().getColor(R.color.accent));
mSet.setDecreasingPaintStyle(Paint.Style.FILL);
mSet.setShadowColor(getResources().getColor(R.color.black));
mCandledata = new CandleData(x, mSet);
//Don't show value text
mCandledata.setDrawValues(false);
mChart.setData(mCandledata);
mChart.invalidate();
}
};
rangeSeekBar.setOnRangeSeekBarChangeListener(skListener);
结果Sceenshots:
初始加载:
最大范围拉近了开始:
最小范围拉近尾声:
答案 0 :(得分:0)
您需要更改蜡烛条目的xIndex
。第一支蜡烛需要xIndex
0
int xIndex = 0;
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
//set the xIndex value
x.setXIndex(xIndex);
y.add(current);
x.add(currentDate);
xIndex++;
}