Search in sources :

Example 26 with LineDataSet

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

the class LineChartActivity1 method setData.

private void setData(int count, float range) {
    ArrayList<Entry> values = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range) + 3;
        values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
    }
    LineDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(values);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(values, "DataSet 1");
        set1.setDrawIcons(false);
        // set the line to be drawn like this "- - - - - -"
        set1.enableDashedLine(10f, 5f, 0f);
        set1.enableDashedHighlightLine(10f, 5f, 0f);
        set1.setColor(Color.BLACK);
        set1.setCircleColor(Color.BLACK);
        set1.setLineWidth(1f);
        set1.setCircleRadius(3f);
        set1.setDrawCircleHole(false);
        set1.setValueTextSize(9f);
        set1.setDrawFilled(true);
        set1.setFormLineWidth(1f);
        set1.setFormLineDashEffect(new DashPathEffect(new float[] { 10f, 5f }, 0f));
        set1.setFormSize(15.f);
        if (Utils.getSDKInt() >= 18) {
            // fill drawable only supported on api level 18 and above
            Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
            set1.setFillDrawable(drawable);
        } else {
            set1.setFillColor(Color.BLACK);
        }
        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        // add the datasets
        dataSets.add(set1);
        // create a data object with the datasets
        LineData data = new LineData(dataSets);
        // set data
        mChart.setData(data);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) DashPathEffect(android.graphics.DashPathEffect)

Example 27 with LineDataSet

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

the class LineChartActivity2 method setData.

private void setData(int count, float range) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = range / 2f;
        float val = (float) (Math.random() * mult) + 50;
        yVals1.add(new Entry(i, val));
    }
    ArrayList<Entry> yVals2 = new ArrayList<Entry>();
    for (int i = 0; i < count - 1; i++) {
        float mult = range;
        float val = (float) (Math.random() * mult) + 450;
        yVals2.add(new Entry(i, val));
    //            if(i == 10) {
    //                yVals2.add(new Entry(i, val + 50));
    //            }
    }
    ArrayList<Entry> yVals3 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = range;
        float val = (float) (Math.random() * mult) + 500;
        yVals3.add(new Entry(i, val));
    }
    LineDataSet set1, set2, set3;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
        set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
        set1.setValues(yVals1);
        set2.setValues(yVals2);
        set3.setValues(yVals3);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(yVals1, "DataSet 1");
        set1.setAxisDependency(AxisDependency.LEFT);
        set1.setColor(ColorTemplate.getHoloBlue());
        set1.setCircleColor(Color.WHITE);
        set1.setLineWidth(2f);
        set1.setCircleRadius(3f);
        set1.setFillAlpha(65);
        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setDrawCircleHole(false);
        //set1.setFillFormatter(new MyFillFormatter(0f));
        //set1.setDrawHorizontalHighlightIndicator(false);
        //set1.setVisible(false);
        //set1.setCircleHoleColor(Color.WHITE);
        // create a dataset and give it a type
        set2 = new LineDataSet(yVals2, "DataSet 2");
        set2.setAxisDependency(AxisDependency.RIGHT);
        set2.setColor(Color.RED);
        set2.setCircleColor(Color.WHITE);
        set2.setLineWidth(2f);
        set2.setCircleRadius(3f);
        set2.setFillAlpha(65);
        set2.setFillColor(Color.RED);
        set2.setDrawCircleHole(false);
        set2.setHighLightColor(Color.rgb(244, 117, 117));
        //set2.setFillFormatter(new MyFillFormatter(900f));
        set3 = new LineDataSet(yVals3, "DataSet 3");
        set3.setAxisDependency(AxisDependency.RIGHT);
        set3.setColor(Color.YELLOW);
        set3.setCircleColor(Color.WHITE);
        set3.setLineWidth(2f);
        set3.setCircleRadius(3f);
        set3.setFillAlpha(65);
        set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
        set3.setDrawCircleHole(false);
        set3.setHighLightColor(Color.rgb(244, 117, 117));
        // create a data object with the datasets
        LineData data = new LineData(set1, set2, set3);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(9f);
        // set data
        mChart.setData(data);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 28 with LineDataSet

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

the class LineChartActivityColored method setupChart.

private void setupChart(LineChart chart, LineData data, int color) {
    ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
    // no description text
    chart.getDescription().setEnabled(false);
    // mChart.setDrawHorizontalGrid(false);
    //
    // enable / disable grid background
    chart.setDrawGridBackground(false);
    //        chart.getRenderer().getGridPaint().setGridColor(Color.WHITE & 0x70FFFFFF);
    // enable touch gestures
    chart.setTouchEnabled(true);
    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    // if disabled, scaling can be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setBackgroundColor(color);
    // set custom chart offsets (automatic offset calculation is hereby disabled)
    chart.setViewPortOffsets(10, 0, 10, 0);
    // add data
    chart.setData(data);
    // get the legend (only possible after setting data)
    Legend l = chart.getLegend();
    l.setEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getAxisLeft().setSpaceTop(40);
    chart.getAxisLeft().setSpaceBottom(40);
    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    // animate calls invalidate()...
    chart.animateX(2500);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) LineDataSet(com.github.mikephil.charting.data.LineDataSet)

Example 29 with LineDataSet

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

the class GraphsFragment method loadSnowChart.

public void loadSnowChart() {
    snowChart.setDrawGridBackground(false);
    snowChart.setBackgroundColor(Color.BLACK);
    snowChart.setTouchEnabled(true);
    snowChart.setDragEnabled(true);
    snowChart.setMaxHighlightDistance(300);
    snowChart.setPinchZoom(true);
    snowChart.setPadding(2, 2, 2, 2);
    snowChart.getLegend().setEnabled(true);
    snowChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = snowChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = snowChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = snowChart.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 (snowChart.getData() != null) {
        snowChart.getData().removeDataSet(snowChart.getData().getDataSetByIndex(snowChart.getData().getDataSetCount() - 1));
        snowChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    set = new LineDataSet(snowEntries, getString(R.string.g_snow));
    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.YELLOW);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    snowChart.setData(data);
    snowChart.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 30 with LineDataSet

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

the class GraphsFragment method loadWindChart.

public void loadWindChart() {
    windChart.setDrawGridBackground(false);
    windChart.setBackgroundColor(Color.BLACK);
    windChart.setTouchEnabled(true);
    windChart.setDragEnabled(true);
    windChart.setMaxHighlightDistance(300);
    windChart.setPinchZoom(true);
    windChart.setPadding(2, 2, 2, 2);
    windChart.getLegend().setEnabled(true);
    windChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = windChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = windChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = windChart.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 (windChart.getData() != null) {
        windChart.getData().removeDataSet(windChart.getData().getDataSetByIndex(windChart.getData().getDataSetCount() - 1));
        windChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    String wind = String.format(Locale.ENGLISH, getString(R.string.g_wind), pf.getUnits().equals("metric") ? getString(R.string.mps) : getString(R.string.mph));
    set = new LineDataSet(windEntries, wind);
    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.RED);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    windChart.setData(data);
    windChart.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)

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