2015-06-28 34 views
0

我正在使用雙向選擇欄來選擇最小和最大範圍。MpAndroidChart CandleStick顯示雙搜索欄的範圍?

它在最大範圍下降時起作用,但是當拉出最小範圍時失效。

範圍搜索條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:

初始加載:

The Initial Chart

最大範圍拉到接近開頭:

Max Range Pulled pulled near beginning

分範圍內拉到接近結束:

Min Range Seekbar pulled near end

回答

0

您需要更改的條目蠟燭的xIndex。第一支蠟燭需要有xIndex0

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++; 
       }