com.github.mikephil.charting.highlight.Highlight类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中com.github.mikephil.charting.highlight.Highlight类的一些代码示例,展示了Highlight类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Highlight类的具体详情如下:
包路径:com.github.mikephil.charting.highlight.Highlight
类名称:Highlight

Highlight介绍

[英]Contains information needed to determine the highlighted value.
[中]包含确定突出显示值所需的信息。

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch
 * point
 * inside the CombinedChart.
 *
 * @param x
 * @param y
 * @return
 */
@Override
public Highlight getHighlightByTouchPoint(float x, float y) {
  if (mData == null) {
    Log.e(LOG_TAG, "Can't select by touch. No data set.");
    return null;
  } else {
    Highlight h = getHighlighter().getHighlight(x, y);
    if (h == null || !isHighlightFullBarEnabled()) return h;
    // For isHighlightFullBarEnabled, remove stackIndex
    return new Highlight(h.getX(), h.getY(),
        h.getXPx(), h.getYPx(),
        h.getDataSetIndex(), -1, h.getAxis());
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
BarEntry e = set.getEntryForXValue(high.getX(), high.getY());
mHighlightPaint.setAlpha(set.getHighLightAlpha());
boolean isStack = (high.getStackIndex() >= 0  && e.isStacked()) ? true : false;
    Range range = e.getRanges()[high.getStackIndex()];

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Highlights upon dragging, generates callbacks for the selection-listener.
 *
 * @param e
 */
private void performHighlightDrag(MotionEvent e) {
  Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
  if (h != null && !h.equalTo(mLastHighlighted)) {
    mLastHighlighted = h;
    mChart.highlightValue(h, true);
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns the actual position in pixels of the MarkerView for the given
 * Highlight object.
 *
 * @param high
 * @return
 */
protected float[] getMarkerPosition(Highlight high) {
  return new float[]{high.getDrawX(), high.getDrawY()};
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Get the Entry for a corresponding highlight object
 *
 * @param highlight
 * @return the entry that is highlighted
 */
public Entry getEntryForHighlight(Highlight highlight) {
  if (highlight.getDataSetIndex() >= mDataSets.size())
    return null;
  else {
    return mDataSets.get(highlight.getDataSetIndex()).getEntryForXValue(highlight.getX(), highlight.getY());
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  if (e == null)
    return;
  Log.i("VAL SELECTED",
      "Value: " + e.getY() + ", index: " + h.getX()
          + ", DataSet index: " + h.getDataSetIndex());
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
  LineData lineData = mChart.getLineData();
  for (Highlight high : indices) {
    ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
    if (set == null || !set.isHighlightEnabled())
      continue;
    Entry e = set.getEntryForXValue(high.getX(), high.getY());
    if (!isInBoundsX(e, set))
      continue;
    MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
        .getPhaseY());
    high.setDraw((float) pix.x, (float) pix.y);
    // draw the lines
    drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Get the Entry for a corresponding highlight object
 *
 * @param highlight
 * @return the entry that is highlighted
 */
@Override
public Entry getEntryForHighlight(Highlight highlight) {
  if (highlight.getDataIndex() >= getAllData().size())
    return null;
  ChartData data = getDataByIndex(highlight.getDataIndex());
  if (highlight.getDataSetIndex() >= data.getDataSetCount())
    return null;
  // The value of the highlighted entry could be NaN -
  //   if we are not interested in highlighting a specific value.
  List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
      .getEntriesForXValue(highlight.getX());
  for (Entry entry : entries)
    if (entry.getY() == highlight.getY() ||
        Float.isNaN(highlight.getY()))
      return entry;
  return null;
}

代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  candleChart.highlightValue(h);
  if (barChart.getData().getBarData().getDataSets().size() != 0) {
    Highlight highlight = new Highlight(h.getX(), h.getDataSetIndex(), h.getStackIndex());
    highlight.setDataIndex(h.getDataIndex());
    barChart.highlightValues(new Highlight[]{highlight});
  } else {
    Highlight highlight = new Highlight(h.getX(), 2, h.getStackIndex());
    highlight.setDataIndex(0);
    barChart.highlightValues(new Highlight[]{highlight});
  }
  updateText(e.getXIndex(), true);
}

代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  barChart.highlightValue(h);
  lineChart.highlightValue(new Highlight(h.getX(), h.getDataSetIndex(), -1));
  if (mHighlightValueSelectedListener != null) {
    mHighlightValueSelectedListener.onDayHighlightValueListener(mData, e.getXIndex(), true);
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

int stackIndex = getClosestStackIndex(ranges, yVal);
MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);
Highlight stackedHigh = new Highlight(
    entry.getX(),
    entry.getY(),
    (float) pixels.x,
    (float) pixels.y,
    high.getDataSetIndex(),
    stackIndex,
    high.getAxis()
);

代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  barChart.highlightValue(h);
  Highlight highlight = new Highlight(h.getX(), 0, h.getStackIndex());
  highlight.setDataIndex(1);
  candleChart.highlightValues(new Highlight[]{highlight});
  updateText(e.getXIndex(), true);
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  BarEntry entry = (BarEntry) e;
  Log.i("VAL SELECTED",
      "Value: " + Math.abs(entry.getYVals()[h.getStackIndex()]));
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Get dataset for highlight
 *
 * @param highlight current highlight
 * @return dataset related to highlight
 */
public IBarLineScatterCandleBubbleDataSet<? extends Entry> getDataSetByHighlight(Highlight highlight) {
  if (highlight.getDataIndex() >= getAllData().size())
    return null;
  BarLineScatterCandleBubbleData data = getDataByIndex(highlight.getDataIndex());
  if (highlight.getDataSetIndex() >= data.getDataSetCount())
    return null;
  return (IBarLineScatterCandleBubbleDataSet<? extends Entry>)
      data.getDataSets().get(highlight.getDataSetIndex());
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public void onValueSelected(Entry e, Highlight h) {
  Log.i("Activity", "Selected: " + e.toString() + ", dataSet: " + h.getDataSetIndex());
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns the Highlight of the DataSet that contains the closest value on the
 * y-axis.
 *
 * @param closestValues        contains two Highlight objects per DataSet closest to the selected x-position (determined by
 *                             rounding up an down)
 * @param x
 * @param y
 * @param axis                 the closest axis
 * @param minSelectionDistance
 * @return
 */
public Highlight getClosestHighlightByPixel(List<Highlight> closestValues, float x, float y,
                      YAxis.AxisDependency axis, float minSelectionDistance) {
  Highlight closest = null;
  float distance = minSelectionDistance;
  for (int i = 0; i < closestValues.size(); i++) {
    Highlight high = closestValues.get(i);
    if (axis == null || high.getAxis() == axis) {
      float cDistance = getDistance(x, y, high.getXPx(), high.getYPx());
      if (cDistance < distance) {
        closest = high;
        distance = cDistance;
      }
    }
  }
  return closest;
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Checks if the given index is set to be highlighted.
 *
 * @param index
 * @return
 */
public boolean needsHighlight(int index) {
  // no highlight
  if (!valuesToHighlight())
    return false;
  for (int i = 0; i < mIndicesToHighlight.length; i++)
    // check if the xvalue for the given dataset needs highlight
    if ((int) mIndicesToHighlight[i].getX() == index)
      return true;
  return false;
}

代码示例来源:origin: PhilJay/MPAndroidChart

Log.i(LOG_TAG, "Highlighted: " + high.toString());

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Highlights the value at the given x-value in the given DataSet. Provide
 * -1 as the dataSetIndex to undo all highlighting.
 *
 * @param x
 * @param dataSetIndex
 * @param stackIndex   the index inside the stack - only relevant for stacked entries
 */
public void highlightValue(float x, int dataSetIndex, int stackIndex) {
  highlightValue(new Highlight(x, dataSetIndex, stackIndex), false);
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
  Chart chart = mChart.get();
  if (chart == null) return;
  for (DataRenderer renderer : mRenderers) {
    ChartData data = null;
    if (renderer instanceof BarChartRenderer)
      data = ((BarChartRenderer)renderer).mChart.getBarData();
    else if (renderer instanceof LineChartRenderer)
      data = ((LineChartRenderer)renderer).mChart.getLineData();
    else if (renderer instanceof CandleStickChartRenderer)
      data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
    else if (renderer instanceof ScatterChartRenderer)
      data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
    else if (renderer instanceof BubbleChartRenderer)
      data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();
    int dataIndex = data == null ? -1
        : ((CombinedData)chart.getData()).getAllData().indexOf(data);
    mHighlightBuffer.clear();
    for (Highlight h : indices) {
      if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
        mHighlightBuffer.add(h);
    }
    renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
  }
}

相关文章