com.github.mikephil.charting.highlight.Highlight Java Examples

The following examples show how to use com.github.mikephil.charting.highlight.Highlight. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch
 * point
 * inside the BarChart.
 *
 * @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());
    }
}
 
Example #2
Source File: BarLineChartTouchListener.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onSingleTapUp(MotionEvent e) {

    mLastGesture = ChartGesture.SINGLE_TAP;

    OnChartGestureListener l = mChart.getOnChartGestureListener();

    if (l != null) {
        l.onChartSingleTapped(e);
    }

    if (!mChart.isHighlightPerTapEnabled()) {
        return false;
    }

    Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
    performHighlight(h, e);

    return super.onSingleTapUp(e);
}
 
Example #3
Source File: FragmentPieChart.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
    ReportBuilder reportBuilder = ReportBuilder.getInstance(getActivity());
    IAbstractModel model = (IAbstractModel) e.getData();
    if (reportBuilder.getParentID() != model.getID() && AbstractModelManager.getAllChildren(model, getActivity()).size() > 0) {
        reportBuilder.setParentID(model.getID());
        updateChart(true);
        return;
    }
    CabbageFormatter cabbageFormatter = null;
    try {
        cabbageFormatter = new CabbageFormatter(reportBuilder.getActiveCabbage());
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    String s = String.format("%s %s", e.getData().toString(), cabbageFormatter.format(new BigDecimal(e.getVal())));
    GradientDrawable bgShape = (GradientDrawable) mImageViewColor.getBackground();
    IPieDataSet dataSet = mPieChart.getData().getDataSet();
    bgShape.setColor(dataSet.getColor(dataSet.getEntryIndex(e)));
    mTextViewSelected.setText(s);

    mFabLayout.setVisibility(View.VISIBLE);
    mImageViewColor.setVisibility(View.VISIBLE);
    mTextViewSelected.setVisibility(View.VISIBLE);
}
 
Example #4
Source File: FragmentBarChart.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
    ReportBuilder reportBuilder = ReportBuilder.getInstance(getActivity());
            IAbstractModel model = (IAbstractModel) e.getData();
            if (reportBuilder.getParentID() != model.getID() && AbstractModelManager.getAllChildren(model, getActivity()).size() > 0) {
                reportBuilder.setParentID(model.getID());
                updateChart();
                return;
            }
    CabbageFormatter cabbageFormatter = null;
    try {
        cabbageFormatter = new CabbageFormatter(reportBuilder.getActiveCabbage());
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    String s = String.format("%s %s", e.getData().toString(), cabbageFormatter.format(new BigDecimal(e.getVal())));
    Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
    mFabLayout.setVisibility(View.VISIBLE);
}
 
Example #5
Source File: ChartMarkerView.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    String value = "";

    switch (mType) {
        case ChartRVAdapter.BATTERY_LEVEL:
            value = StringHelper.formatPercentageNumber(e.getY());
            break;
        case ChartRVAdapter.BATTERY_TEMPERATURE:
            value = StringHelper.formatNumber(e.getY()) + " ºC";
            break;
        case ChartRVAdapter.BATTERY_VOLTAGE:
            value = StringHelper.formatNumber(e.getY()) + " V";
            break;
    }

    mContent.setText(value);

    // this will perform necessary layouting
    super.refreshContent(e, highlight);
}
 
Example #6
Source File: ChartData.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * 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 {
        // The value of the highlighted entry could be NaN -
        //   if we are not interested in highlighting a specific value.

        List<?> entries = mDataSets.get(highlight.getDataSetIndex())
                .getEntriesForXIndex(highlight.getXIndex());
        for (Object entry : entries)
            if (((Entry)entry).getVal() == highlight.getValue() ||
                    Float.isNaN(highlight.getValue()))
                return (Entry)entry;

        return null;
    }
}
 
Example #7
Source File: ChartInfoViewHandler.java    From android-kline with Apache License 2.0 6 votes vote down vote up
public ChartInfoViewHandler(BarLineChartBase chart) {
    mChart = chart;
    mDetector = new GestureDetector(mChart.getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
            mIsLongPress = true;
            Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
            if (h != null) {
                mChart.highlightValue(h, true);
                mChart.disableScroll();
            }
        }

    });
}
 
Example #8
Source File: CombinedChartCurrentDay.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the Entry for a corresponding highlight object
 *
 * @param highlight
 * @return the entry that is highlighted
 */
public Entry getEntryForHighlight(Highlight highlight) {

    List<BarLineScatterCandleBubbleData> dataObjects = mData.getAllData();

    if (highlight.getDataIndex() >= dataObjects.size())
        return null;

    ChartData data = dataObjects.get(highlight.getDataIndex());

    if (highlight.getDataSetIndex() >= data.getDataSetCount())
        return null;
    else {
        // 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());

        return entries.get(0);
    }
}
 
Example #9
Source File: BarLineChartTouchListener.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #10
Source File: DataMarkView.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
    public void refreshContent(Entry e, Highlight highlight) {
//        if (e instanceof CandleEntry) {
//            CandleEntry ce = (CandleEntry) e;
////            tvContent.setText(Utils.formatNumber(ce.getHigh() * multiply, digits, true) + unit);
//        } else {
//            tvContent.setText(e.getX() + unit + ":" + e.getY());
//        }
        tvContent.setText(iDataValueFormat.format(e, highlight));
    }
 
Example #11
Source File: Chart.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

        Highlight highlight = mIndicesToHighlight[i];

        IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex());

        Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
        int entryIndex = set.getEntryIndex(e);

        // make sure entry not null
        if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX())
            continue;

        float[] pos = getMarkerPosition(highlight);

        // check bounds
        if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
            continue;

        // callbacks to update the content
        mMarker.refreshContent(e, highlight);

        // draw the marker
        mMarker.draw(canvas, pos[0], pos[1]);
    }
}
 
Example #12
Source File: ProductDetailActivity.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #13
Source File: FragmentTimeBarChart.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {CabbageFormatter cabbageFormatter = null;
    try {
        cabbageFormatter = new CabbageFormatter(ReportBuilder.getInstance(getActivity()).getActiveCabbage());
        DateRangeSum rangeSum = (DateRangeSum) e.getData();
        String s = String.format("%s", cabbageFormatter.format(rangeSum.getSum()));
        Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    mFabLayout.setVisibility(View.VISIBLE);
}
 
Example #14
Source File: Results.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void setRNEData(List<Double> classRangeValue) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();

    // IMPORTANT: In a PieChart, no values (Entry) should have the same
    // xIndex (even if from different DataSets), since no values can be
    // drawn above each other.
    catNE= getResources().getStringArray(R.array.catNE_list_array);
    ArrayList<String> xVals = new ArrayList<String>();
    double maxValue = 0;
    int maxClassId = 0;
    for (int idEntry = 0; idEntry < classRangeValue.size(); idEntry++) {
        float value = classRangeValue.get(classRangeValue.size() - 1 - idEntry).floatValue();
        // Fix background color issue if the pie is too thin
        if(value < 0.01) {
            value = 0;
        }
        yVals1.add(new Entry(value, idEntry));
        xVals.add(catNE[idEntry]);
        if (value > maxValue) {
            maxClassId = idEntry;
            maxValue = value;
        }
    }

    PieDataSet dataSet = new PieDataSet(yVals1,Results.this.getString(R.string.caption_SL));
    dataSet.setSliceSpace(3f);
    dataSet.setColors(NE_COLORS);

    PieData data = new PieData(xVals, dataSet);
    data.setValueFormatter(new CustomPercentFormatter());
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.BLACK);
    rneChart.setData(data);

    // highlight the maximum value of the RNE
    // Find the maximum of the array, in order to be highlighted
    Highlight h = new Highlight(maxClassId, 0);
    rneChart.highlightValues(new Highlight[] { h });
    rneChart.invalidate();
}
 
Example #15
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * returns the DataSet object displayed at the touched position of the chart
 *
 * @param x
 * @param y
 * @return
 */
public IBarLineScatterCandleBubbleDataSet getDataSetByTouchPoint(float x, float y) {
    Highlight h = getHighlightByTouchPoint(x, y);
    if (h != null) {
        return mData.getDataSetByIndex(h.getDataSetIndex());
    }
    return null;
}
 
Example #16
Source File: CombinedChartRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@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()]));
    }
}
 
Example #17
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #18
Source File: PieChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Highlight highlight) {

    MPPointF center = getCenterCircleBox();
    float r = getRadius();

    float off = r / 10f * 3.6f;

    if (isDrawHoleEnabled()) {
        off = (r - (r / 100f * getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    float rotationAngle = getRotationAngle();

    int entryIndex = (int) highlight.getX();

    // offset needed to center the drawn text in the slice
    float offset = mDrawAngles[entryIndex] / 2;

    // calculate the text position
    float x = (float) (r
            * Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
            * mAnimator.getPhaseY())) + center.x);
    float y = (float) (r
            * Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
            * mAnimator.getPhaseY())) + center.y);

    MPPointF.recycleInstance(center);
    return new float[]{x, y};
}
 
Example #19
Source File: StackedBarActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {

	BarEntry entry = (BarEntry) e;

	if (entry.getVals() != null)
		Log.i("VAL SELECTED", "Value: " + entry.getVals()[h.getStackIndex()]);
	else
		Log.i("VAL SELECTED", "Value: " + entry.getVal());
}
 
Example #20
Source File: ChartMarkerView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    Object[] extraData = (Object[])e.getData();
    ScaleMeasurement measurement = (ScaleMeasurement)extraData[0];
    ScaleMeasurement prevMeasurement = (ScaleMeasurement)extraData[1];
    FloatMeasurementView measurementView = (FloatMeasurementView)extraData[2];

    SpannableStringBuilder markerText = new SpannableStringBuilder();

    if (measurement != null) {
        measurementView.loadFrom(measurement, prevMeasurement);
        DateFormat dateFormat = DateFormat.getDateInstance();
        markerText.append(dateFormat.format(measurement.getDateTime()));
        markerText.setSpan(new RelativeSizeSpan(0.8f), 0, markerText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        markerText.append("\n");

        if (measurement.isAverageValue()) {
            markerText.append("Ø ");
        }
    }

    markerText.append(measurementView.getValueAsString(true));

    if (prevMeasurement != null) {
        markerText.append("\n");
        int textPosAfterSymbol = markerText.length() + 1;

        measurementView.appendDiffValue(markerText, false);

        // set color diff value to text color
        if (markerText.length() > textPosAfterSymbol) {
            markerText.setSpan(new ForegroundColorSpan(ColorUtil.COLOR_WHITE), textPosAfterSymbol, markerText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

    markerText.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER),0, markerText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    markerTextField.setText(markerText);

    super.refreshContent(e, highlight);
}
 
Example #21
Source File: RadarChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Entry e, Highlight highlight) {

    float angle = getSliceAngle() * e.getXIndex() + getRotationAngle();
    float val = e.getVal() * getFactor();
    PointF c = getCenterOffsets();

    PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))),
            (float) (c.y + val * Math.sin(Math.toRadians(angle))));

    return new float[]{
            p.x, p.y
    };
}
 
Example #22
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * returns the Entry object displayed at the touched position of the chart
 *
 * @param x
 * @param y
 * @return
 */
public Entry getEntryByTouchPoint(float x, float y) {
    Highlight h = getHighlightByTouchPoint(x, y);
    if (h != null) {
        return mData.getEntryForHighlight(h);
    }
    return null;
}
 
Example #23
Source File: LineChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    for (int i = 0; i < indices.length; i++) {

        ILineDataSet set = mChart.getLineData().getDataSetByIndex(indices[i]
                .getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        int xIndex = indices[i].getXIndex(); // get the
        // x-position

        if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
            continue;

        final float yVal = set.getYValForXIndex(xIndex);
        if (yVal == Float.NaN)
            continue;

        float y = yVal * mAnimator.getPhaseY(); // get
        // the
        // y-position

        float[] pts = new float[]{
                xIndex, y
        };

        mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

        // draw the lines
        drawHighlightLines(c, pts, set);
    }
}
 
Example #24
Source File: BarLineChartTouchListener.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #25
Source File: HorizontalBarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch point
 * inside the BarChart.
 * 
 * @param x
 * @param y
 * @return
 */
@Override
public Highlight getHighlightByTouchPoint(float x, float y) {

	if (mDataNotSet || mData == null) {
		Log.e(LOG_TAG, "Can't select by touch. No data set.");
		return null;
	} else
		return mHighlighter.getHighlight(y, x); // switch x and y
}
 
Example #26
Source File: GraphFragment.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onValueSelected(Entry e, Highlight h) {
    Object[] extraData = (Object[])e.getData();

    if (extraData == null) {
        return;
    }

    markedMeasurement = (ScaleMeasurement)extraData[0];
    //MeasurementView measurementView = (MeasurementView)extraData[1];

    showMenu.setVisibility(View.VISIBLE);
    editMenu.setVisibility(View.VISIBLE);
    deleteMenu.setVisibility(View.VISIBLE);
}
 
Example #27
Source File: ChartTouchListener.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Perform a highlight operation.
 *
 * @param e
 */
protected void performHighlight(Highlight h, MotionEvent e) {

    if (h == null || h.equalTo(mLastHighlighted)) {
        mChart.highlightValue(null, true);
        mLastHighlighted = null;
    } else {
        mChart.highlightValue(h, true);
        mLastHighlighted = h;
    }
}
 
Example #28
Source File: BarLineChartTouchListener.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a highlight operation.
 * 
 * @param e
 */
private void performHighlight(MotionEvent e) {

    Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());

    if (h == null || h.equalTo(mLastHighlighted)) {
        mChart.highlightTouch(null);
        mLastHighlighted = null;
    } else {
        mLastHighlighted = h;
        mChart.highlightTouch(h);
    }
}
 
Example #29
Source File: BeesMarkerView.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    if (e instanceof CandleEntry) {
        CandleEntry ce = (CandleEntry) e;
        tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
    } else {
        tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
    }
    super.refreshContent(e, highlight);
}
 
Example #30
Source File: BarLineChartBase.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * returns the Entry object displayed at the touched position of the chart
 *
 * @param x
 * @param y
 * @return
 */
public Entry getEntryByTouchPoint(float x, float y) {
    Highlight h = getHighlightByTouchPoint(x, y);
    if (h != null) {
        return mData.getEntryForHighlight(h);
    }
    return null;
}