1

使用 TimeSeries 缩放或平移散点图后,将根据屏幕上的内容计算 pointIndex 点。

如果一个系列中有 10 个项目,当图表第一次显示时,项目 1 位于 pointIndex 0。项目 2 位于 pointIndex 1,依此类推。但是,一旦您缩放或平移,则 pointIndex 以 SHOWN 开头,而不是系列中项目的索引。

有没有人想出一种方法来获取点的系列索引值而不是平移/缩放的索引值?

4

1 回答 1

1

我通过更改名为getRange的XYSeries的方法来解决这个问题。

public synchronized RangeHolderWithDiff getRange(double start, double stop,
  boolean beforeAfterPoints) {
int diff = 0;
if (beforeAfterPoints) {
  // we need to add one point before the start and one point after the end
  // (if
  // there are any)
  // to ensure that line doesn't end before the end of the screen

  // this would be simply: start = mXY.lowerKey(start) but NavigableMap is
  // available since API 9
  SortedMap<Double, Double> headMap = mXY.headMap(start);
  if (!headMap.isEmpty()) {
    start = headMap.lastKey();
    diff = headMap.size();
    System.out.println("DIFF IS " + diff);
  }

  // this would be simply: end = mXY.higherKey(end) but NavigableMap is
  // available since API 9
  // so we have to do this hack in order to support older versions
  SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
  if (!tailMap.isEmpty()) {
    Iterator<Double> tailIterator = tailMap.keySet().iterator();
    Double next = tailIterator.next();
    if (tailIterator.hasNext()) {
      stop = tailIterator.next();
    } else {
      stop += next;
    }
  }
}
RangeHolderWithDiff mRangeHolderWithDiff = new RangeHolderWithDiff();
mRangeHolderWithDiff.indexDiff = diff;
mRangeHolderWithDiff.sortedMap = mXY.subMap(start, stop);
return mRangeHolderWithDiff;

}

diff 变量为您提供了额外的 x 值计数,我正在尝试将此参数添加到 touchAreas。如果我能做到这一点,我将编辑我的答案。祝你好运。

于 2014-01-13T19:23:04.437 回答