Search in sources :

Example 1 with ChartData

use of com.github.mikephil.charting.data.ChartData in project Gadgetbridge by Freeyourgadget.

the class LiveActivityFragment method addEntries.

private void addEntries(int timestamp) {
    mTotalStepsChart.setSingleEntryYValue(mSteps.getTotalSteps());
    YAxis stepsPerMinuteCurrentYAxis = mStepsPerMinuteCurrentChart.getAxisLeft();
    int maxStepsPerMinute = mSteps.getMaxStepsPerMinute();
    //        int extraRoom = maxStepsPerMinute/5;
    //        buggy in MPAndroidChart? Disable.
    //        stepsPerMinuteCurrentYAxis.setAxisMaxValue(Math.max(MIN_STEPS_PER_MINUTE, maxStepsPerMinute + extraRoom));
    LimitLine target = new LimitLine(maxStepsPerMinute);
    stepsPerMinuteCurrentYAxis.removeAllLimitLines();
    stepsPerMinuteCurrentYAxis.addLimitLine(target);
    int stepsPerMinute = mSteps.getStepsPerMinute(true);
    mStepsPerMinuteCurrentChart.setSingleEntryYValue(stepsPerMinute);
    if (!addHistoryDataSet(false)) {
        return;
    }
    ChartData data = mStepsPerMinuteHistoryChart.getData();
    if (stepsPerMinute < 0) {
        stepsPerMinute = 0;
    }
    mHistorySet.addEntry(new Entry(timestamp, stepsPerMinute));
    int hr = getCurrentHeartRate();
    if (hr < 0) {
        hr = 0;
    }
    mHeartRateSet.addEntry(new Entry(timestamp, hr));
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) ChartData(com.github.mikephil.charting.data.ChartData) LimitLine(com.github.mikephil.charting.components.LimitLine) Paint(android.graphics.Paint) YAxis(com.github.mikephil.charting.components.YAxis)

Example 2 with ChartData

use of com.github.mikephil.charting.data.ChartData 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 3 with ChartData

use of com.github.mikephil.charting.data.ChartData in project MPAndroidChart by PhilJay.

the class CombinedHighlighter method getHighlightsAtXValue.

@Override
protected List<Highlight> getHighlightsAtXValue(float xVal, float x, float y) {
    mHighlightBuffer.clear();
    List<BarLineScatterCandleBubbleData> dataObjects = mChart.getCombinedData().getAllData();
    for (int i = 0; i < dataObjects.size(); i++) {
        ChartData dataObject = dataObjects.get(i);
        // in case of BarData, let the BarHighlighter take over
        if (barHighlighter != null && dataObject instanceof BarData) {
            Highlight high = barHighlighter.getHighlight(x, y);
            if (high != null) {
                high.setDataIndex(i);
                mHighlightBuffer.add(high);
            }
        } else {
            for (int j = 0, dataSetCount = dataObject.getDataSetCount(); j < dataSetCount; j++) {
                IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);
                // don't include datasets that cannot be highlighted
                if (!dataSet.isHighlightEnabled())
                    continue;
                List<Highlight> highs = buildHighlights(dataSet, j, xVal, DataSet.Rounding.CLOSEST);
                for (Highlight high : highs) {
                    high.setDataIndex(i);
                    mHighlightBuffer.add(high);
                }
            }
        }
    }
    return mHighlightBuffer;
}
Also used : ChartData(com.github.mikephil.charting.data.ChartData) BarData(com.github.mikephil.charting.data.BarData) BarLineScatterCandleBubbleData(com.github.mikephil.charting.data.BarLineScatterCandleBubbleData) IDataSet(com.github.mikephil.charting.interfaces.datasets.IDataSet)

Aggregations

ChartData (com.github.mikephil.charting.data.ChartData)3 Paint (android.graphics.Paint)1 Chart (com.github.mikephil.charting.charts.Chart)1 CombinedChart (com.github.mikephil.charting.charts.CombinedChart)1 LimitLine (com.github.mikephil.charting.components.LimitLine)1 YAxis (com.github.mikephil.charting.components.YAxis)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 BarLineScatterCandleBubbleData (com.github.mikephil.charting.data.BarLineScatterCandleBubbleData)1 CombinedData (com.github.mikephil.charting.data.CombinedData)1 Entry (com.github.mikephil.charting.data.Entry)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 IDataSet (com.github.mikephil.charting.interfaces.datasets.IDataSet)1