Search in sources :

Example 11 with LineDataSet

use of com.github.mikephil.charting.data.LineDataSet in project Weather by Sparker0i.

the class GraphsFragment method loadRainChart.

public void loadRainChart() {
    rainChart.setDrawGridBackground(false);
    rainChart.setBackgroundColor(Color.BLACK);
    rainChart.setTouchEnabled(true);
    rainChart.setDragEnabled(true);
    rainChart.setMaxHighlightDistance(300);
    rainChart.setPinchZoom(true);
    rainChart.setPadding(2, 2, 2, 2);
    rainChart.getLegend().setEnabled(true);
    rainChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = rainChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = rainChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = rainChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (rainChart.getData() != null) {
        rainChart.getData().removeDataSet(rainChart.getData().getDataSetByIndex(rainChart.getData().getDataSetCount() - 1));
        rainChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    set = new LineDataSet(rainEntries, getString(R.string.g_rain));
    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.GREEN);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    rainChart.setData(data);
    rainChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 12 with LineDataSet

use of com.github.mikephil.charting.data.LineDataSet in project Weather by Sparker0i.

the class GraphsFragment method loadTemperatureChart.

public void loadTemperatureChart() {
    temperatureChart.setDrawGridBackground(false);
    temperatureChart.setBackgroundColor(Color.BLACK);
    temperatureChart.setTouchEnabled(true);
    temperatureChart.setDragEnabled(true);
    temperatureChart.setMaxHighlightDistance(300);
    temperatureChart.setPinchZoom(true);
    temperatureChart.setPadding(2, 2, 2, 2);
    temperatureChart.getLegend().setEnabled(true);
    temperatureChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = temperatureChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = temperatureChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = temperatureChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (temperatureChart.getData() != null) {
        temperatureChart.getData().removeDataSet(temperatureChart.getData().getDataSetByIndex(temperatureChart.getData().getDataSetCount() - 1));
        temperatureChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    String temp = String.format(Locale.ENGLISH, getString(R.string.g_temp), pf.getUnits().equals("metric") ? getString(R.string.c) : getString(R.string.f));
    set = new LineDataSet(tempEntries, temp);
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.MAGENTA);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    temperatureChart.setData(data);
    temperatureChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 13 with LineDataSet

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

the class AbstractChartFragment method createHeartrateSet.

protected LineDataSet createHeartrateSet(List<Entry> values, String label) {
    LineDataSet set1 = new LineDataSet(values, label);
    set1.setLineWidth(0.8f);
    set1.setColor(HEARTRATE_COLOR);
    //        set1.setDrawCubic(true);
    set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set1.setCubicIntensity(0.1f);
    set1.setDrawCircles(false);
    //        set1.setCircleRadius(2f);
    //        set1.setDrawFilled(true);
    //        set1.setColor(getResources().getColor(android.R.color.background_light));
    //        set1.setCircleColor(HEARTRATE_COLOR);
    //        set1.setFillColor(ColorTemplate.getHoloBlue());
    //        set1.setHighLightColor(Color.rgb(128, 0, 255));
    //        set1.setColor(Color.rgb(89, 178, 44));
    set1.setDrawValues(true);
    set1.setValueTextColor(CHART_TEXT_COLOR);
    set1.setAxisDependency(YAxis.AxisDependency.RIGHT);
    return set1;
}
Also used : LineDataSet(com.github.mikephil.charting.data.LineDataSet)

Example 14 with LineDataSet

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

the class AbstractChartFragment method refresh.

protected DefaultChartsData<CombinedData> refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
    //        Calendar cal = GregorianCalendar.getInstance();
    //        cal.clear();
    TimestampTranslation tsTranslation = new TimestampTranslation();
    //        Date date;
    //        String dateStringFrom = "";
    //        String dateStringTo = "";
    //        ArrayList<String> xLabels = null;
    LOG.info("" + getTitle() + ": number of samples:" + samples.size());
    CombinedData combinedData;
    if (samples.size() > 1) {
        boolean annotate = true;
        boolean use_steps_as_movement;
        int last_type = ActivityKind.TYPE_UNKNOWN;
        int numEntries = samples.size();
        List<BarEntry> activityEntries = new ArrayList<>(numEntries);
        boolean hr = supportsHeartrate(gbDevice);
        List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
        // this is kinda inefficient...
        List<Integer> colors = new ArrayList<>(numEntries);
        int lastHrSampleIndex = -1;
        for (int i = 0; i < numEntries; i++) {
            ActivitySample sample = samples.get(i);
            int type = sample.getKind();
            int ts = tsTranslation.shorten(sample.getTimestamp());
            //                System.out.println(ts);
            //                ts = i;
            // determine start and end dates
            //                if (i == 0) {
            //                    cal.setTimeInMillis(ts * 1000L); // make sure it's converted to long
            //                    date = cal.getTime();
            //                    dateStringFrom = dateFormat.format(date);
            //                } else if (i == samples.size() - 1) {
            //                    cal.setTimeInMillis(ts * 1000L); // same here
            //                    date = cal.getTime();
            //                    dateStringTo = dateFormat.format(date);
            //                }
            float movement = sample.getIntensity();
            float value = movement;
            switch(type) {
                case ActivityKind.TYPE_DEEP_SLEEP:
                    value += SleepUtils.Y_VALUE_DEEP_SLEEP;
                    colors.add(akDeepSleep.color);
                    break;
                case ActivityKind.TYPE_LIGHT_SLEEP:
                    colors.add(akLightSleep.color);
                    break;
                case ActivityKind.TYPE_NOT_WORN:
                    //a small value, just to show something on the graphs
                    value = SleepUtils.Y_VALUE_DEEP_SLEEP;
                    colors.add(akNotWorn.color);
                    break;
                default:
                    //                        short steps = sample.getSteps();
                    //                        if (use_steps_as_movement && steps != 0) {
                    //                            // I'm not sure using steps for this is actually a good idea
                    //                            movement = steps;
                    //                        }
                    //                        value = ((float) movement) / movement_divisor;
                    colors.add(akActivity.color);
            }
            activityEntries.add(createBarEntry(value, ts));
            if (hr && isValidHeartRateValue(sample.getHeartRate())) {
                if (lastHrSampleIndex > -1 && ts - lastHrSampleIndex > 60 * HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) {
                    heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1));
                    heartrateEntries.add(createLineEntry(0, ts - 1));
                }
                heartrateEntries.add(createLineEntry(sample.getHeartRate(), ts));
                lastHrSampleIndex = ts;
            }
            String xLabel = "";
            if (annotate) {
            //                    cal.setTimeInMillis((ts + tsOffset) * 1000L);
            //                    date = cal.getTime();
            //                    String dateString = annotationDateFormat.format(date);
            //                    xLabel = dateString;
            //                    if (last_type != type) {
            //                        if (isSleep(last_type) && !isSleep(type)) {
            //                            // woken up
            //                            LimitLine line = new LimitLine(i, dateString);
            //                            line.enableDashedLine(8, 8, 0);
            //                            line.setTextColor(Color.WHITE);
            //                            line.setTextSize(15);
            //                            chart.getXAxis().addLimitLine(line);
            //                        } else if (!isSleep(last_type) && isSleep(type)) {
            //                            // fallen asleep
            //                            LimitLine line = new LimitLine(i, dateString);
            //                            line.enableDashedLine(8, 8, 0);
            //                            line.setTextSize(15);
            //                            line.setTextColor(Color.WHITE);
            //                            chart.getXAxis().addLimitLine(line);
            //                        }
            //                    }
            //                    last_type = type;
            }
        }
        BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
        // create a data object with the datasets
        //            combinedData = new CombinedData(xLabels);
        combinedData = new CombinedData();
        List<IBarDataSet> list = new ArrayList<>();
        list.add(activitySet);
        BarData barData = new BarData(list);
        barData.setBarWidth(100f);
        //            barData.setGroupSpace(0);
        combinedData.setData(barData);
        if (hr && heartrateEntries.size() > 0) {
            LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
            LineData lineData = new LineData(heartrateSet);
            combinedData.setData(lineData);
        }
    //            chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
    //            chart.setDescriptionPosition(?, ?);
    } else {
        combinedData = new CombinedData();
    }
    IAxisValueFormatter xValueFormatter = new SampleXLabelFormatter(tsTranslation);
    return new DefaultChartsData(combinedData, xValueFormatter);
}
Also used : AbstractActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample) ActivitySample(nodomain.freeyourgadget.gadgetbridge.model.ActivitySample) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) CombinedData(com.github.mikephil.charting.data.CombinedData) BarEntry(com.github.mikephil.charting.data.BarEntry) Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) LineData(com.github.mikephil.charting.data.LineData) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet)

Example 15 with LineDataSet

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

the class LiveActivityFragment method setupHistoryChart.

private void setupHistoryChart(BarLineChartBase chart) {
    configureBarLineChartDefaults(chart);
    // no zooming or anything, because it's updated all the time
    chart.setTouchEnabled(false);
    chart.setBackgroundColor(BACKGROUND_COLOR);
    chart.getDescription().setTextColor(DESCRIPTION_COLOR);
    chart.getDescription().setText(getString(R.string.live_activity_steps_per_minute_history));
    chart.setNoDataText(getString(R.string.live_activity_start_your_activity));
    chart.getLegend().setEnabled(false);
    Paint infoPaint = chart.getPaint(Chart.PAINT_INFO);
    infoPaint.setTextSize(Utils.convertDpToPixel(20f));
    infoPaint.setFakeBoldText(true);
    chart.setPaint(infoPaint, Chart.PAINT_INFO);
    XAxis x = chart.getXAxis();
    x.setDrawLabels(true);
    x.setDrawGridLines(false);
    x.setEnabled(true);
    x.setTextColor(CHART_TEXT_COLOR);
    x.setDrawLimitLinesBehindData(true);
    YAxis y = chart.getAxisLeft();
    y.setDrawGridLines(false);
    y.setDrawTopYLabelEntry(false);
    y.setTextColor(CHART_TEXT_COLOR);
    y.setEnabled(true);
    y.setAxisMinimum(0);
    YAxis yAxisRight = chart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setEnabled(true);
    yAxisRight.setDrawLabels(true);
    yAxisRight.setDrawTopYLabelEntry(false);
    yAxisRight.setTextColor(CHART_TEXT_COLOR);
    yAxisRight.setAxisMaximum(HeartRateUtils.MAX_HEART_RATE_VALUE);
    yAxisRight.setAxisMinimum(HeartRateUtils.MIN_HEART_RATE_VALUE);
    mHistorySet = new LineDataSet(new ArrayList<Entry>(), getString(R.string.live_activity_steps_history));
    mHistorySet.setAxisDependency(YAxis.AxisDependency.LEFT);
    mHistorySet.setColor(akActivity.color);
    mHistorySet.setDrawCircles(false);
    mHistorySet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    mHistorySet.setDrawFilled(true);
    mHistorySet.setDrawValues(false);
    mHeartRateSet = createHeartrateSet(new ArrayList<Entry>(), getString(R.string.live_activity_heart_rate));
    mHeartRateSet.setDrawValues(false);
}
Also used : LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

LineDataSet (com.github.mikephil.charting.data.LineDataSet)32 LineData (com.github.mikephil.charting.data.LineData)23 Entry (com.github.mikephil.charting.data.Entry)19 ArrayList (java.util.ArrayList)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)15 Paint (android.graphics.Paint)6 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 Legend (com.github.mikephil.charting.components.Legend)3 BarEntry (com.github.mikephil.charting.data.BarEntry)3 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 DashPathEffect (android.graphics.DashPathEffect)1 Drawable (android.graphics.drawable.Drawable)1 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 CombinedData (com.github.mikephil.charting.data.CombinedData)1