Search in sources :

Example 6 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class BarChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    BarData barData = mChart.getBarData();
    for (Highlight high : indices) {
        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        Transformer trans = mChart.getTransformer(set.getAxisDependency());
        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());
        boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;
        final float y1;
        final float y2;
        if (isStack) {
            if (mChart.isHighlightFullBarEnabled()) {
                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();
            } else {
                Range range = e.getRanges()[high.getStackIndex()];
                y1 = range.from;
                y2 = range.to;
            }
        } else {
            y1 = e.getY();
            y2 = 0.f;
        }
        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);
        setHighlightDrawPos(high, mBarRect);
        c.drawRect(mBarRect, mHighlightPaint);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) Transformer(com.github.mikephil.charting.utils.Transformer) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Range(com.github.mikephil.charting.highlight.Range) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 7 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class CandleStickChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    CandleData candleData = mChart.getCandleData();
    for (Highlight high : indices) {
        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        float y = (lowValue + highValue) / 2f;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 8 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class CombinedChartRenderer method drawHighlighted.

@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()]));
    }
}
Also used : ChartData(com.github.mikephil.charting.data.ChartData) Highlight(com.github.mikephil.charting.highlight.Highlight) CombinedData(com.github.mikephil.charting.data.CombinedData) Chart(com.github.mikephil.charting.charts.Chart) CombinedChart(com.github.mikephil.charting.charts.CombinedChart)

Example 9 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class ScatterChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    ScatterData scatterData = mChart.getScatterData();
    for (Highlight high : indices) {
        IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        final 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);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) MPPointD(com.github.mikephil.charting.utils.MPPointD) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 10 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class BarLineChartTouchListener method onSingleTapUp.

@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);
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight)

Aggregations

Highlight (com.github.mikephil.charting.highlight.Highlight)13 Entry (com.github.mikephil.charting.data.Entry)5 MPPointD (com.github.mikephil.charting.utils.MPPointD)3 DatePickerDialog (android.app.DatePickerDialog)2 Paint (android.graphics.Paint)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 DatePicker (android.widget.DatePicker)2 Toast (android.widget.Toast)2 Description (com.github.mikephil.charting.components.Description)2 PieEntry (com.github.mikephil.charting.data.PieEntry)2 OnChartValueSelectedListener (com.github.mikephil.charting.listener.OnChartValueSelectedListener)2 Transformer (com.github.mikephil.charting.utils.Transformer)2 Calendar (java.util.Calendar)2 SuppressLint (android.annotation.SuppressLint)1 Chart (com.github.mikephil.charting.charts.Chart)1 CombinedChart (com.github.mikephil.charting.charts.CombinedChart)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 BubbleData (com.github.mikephil.charting.data.BubbleData)1