Search in sources :

Example 66 with Entry

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

the class MultiLineChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    mChart.resetTracking();
    tvX.setText("" + (mSeekBarX.getProgress()));
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    for (int z = 0; z < 3; z++) {
        ArrayList<Entry> values = new ArrayList<Entry>();
        for (int i = 0; i < mSeekBarX.getProgress(); i++) {
            double val = (Math.random() * mSeekBarY.getProgress()) + 3;
            values.add(new Entry(i, (float) val));
        }
        LineDataSet d = new LineDataSet(values, "DataSet " + (z + 1));
        d.setLineWidth(2.5f);
        d.setCircleRadius(4f);
        int color = mColors[z % mColors.length];
        d.setColor(color);
        d.setCircleColor(color);
        dataSets.add(d);
    }
    // make the first DataSet dashed
    ((LineDataSet) dataSets.get(0)).enableDashedLine(10, 10, 0);
    ((LineDataSet) dataSets.get(0)).setColors(ColorTemplate.VORDIPLOM_COLORS);
    ((LineDataSet) dataSets.get(0)).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);
    LineData data = new LineData(dataSets);
    mChart.setData(data);
    mChart.invalidate();
}
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)

Example 67 with Entry

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

the class PerformanceLineChart method setData.

private void setData(int count, float range) {
    ArrayList<Entry> yVals = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = (range + 1);
        // + (float)
        float val = (float) (Math.random() * mult) + 3;
        // ((mult *
        // 0.1) / 10);
        yVals.add(new Entry(i * 0.001f, val));
    }
    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
    set1.setColor(Color.BLACK);
    set1.setLineWidth(0.5f);
    set1.setDrawValues(false);
    set1.setDrawCircles(false);
    set1.setMode(LineDataSet.Mode.LINEAR);
    set1.setDrawFilled(false);
    // create a data object with the datasets
    LineData data = new LineData(set1);
    // set data
    mChart.setData(data);
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) Legend(com.github.mikephil.charting.components.Legend) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 68 with Entry

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

the class SimpleFragment method generateScatterData.

protected ScatterData generateScatterData(int dataSets, float range, int count) {
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();
    for (int i = 0; i < dataSets; i++) {
        ArrayList<Entry> entries = new ArrayList<Entry>();
        for (int j = 0; j < count; j++) {
            entries.add(new Entry(j, (float) (Math.random() * range) + range / 4));
        }
        ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
        ds.setScatterShapeSize(12f);
        ds.setScatterShape(shapes[i % shapes.length]);
        ds.setColors(ColorTemplate.COLORFUL_COLORS);
        ds.setScatterShapeSize(9f);
        sets.add(ds);
    }
    ScatterData d = new ScatterData(sets);
    d.setValueTypeface(tf);
    return d;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 69 with Entry

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

the class ScatterChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tvX.setText("" + (mSeekBarX.getProgress() + 1));
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    ArrayList<Entry> yVals2 = new ArrayList<Entry>();
    ArrayList<Entry> yVals3 = new ArrayList<Entry>();
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals1.add(new Entry(i, val));
    }
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals2.add(new Entry(i + 0.33f, val));
    }
    for (int i = 0; i < mSeekBarX.getProgress(); i++) {
        float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
        yVals3.add(new Entry(i + 0.66f, val));
    }
    // create a dataset and give it a type
    ScatterDataSet set1 = new ScatterDataSet(yVals1, "DS 1");
    set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
    ScatterDataSet set2 = new ScatterDataSet(yVals2, "DS 2");
    set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    set2.setScatterShapeHoleColor(ColorTemplate.COLORFUL_COLORS[3]);
    set2.setScatterShapeHoleRadius(3f);
    set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);
    ScatterDataSet set3 = new ScatterDataSet(yVals3, "DS 3");
    set3.setShapeRenderer(new CustomScatterShapeRenderer());
    set3.setColor(ColorTemplate.COLORFUL_COLORS[2]);
    set1.setScatterShapeSize(8f);
    set2.setScatterShapeSize(8f);
    set3.setScatterShapeSize(8f);
    ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
    // add the datasets
    dataSets.add(set1);
    dataSets.add(set2);
    dataSets.add(set3);
    // create a data object with the datasets
    ScatterData data = new ScatterData(dataSets);
    data.setValueTypeface(mTfLight);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : Entry(com.github.mikephil.charting.data.Entry) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) CustomScatterShapeRenderer(com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 70 with Entry

use of com.github.mikephil.charting.data.Entry 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)

Aggregations

Entry (com.github.mikephil.charting.data.Entry)83 ArrayList (java.util.ArrayList)34 Paint (android.graphics.Paint)27 LineData (com.github.mikephil.charting.data.LineData)20 LineDataSet (com.github.mikephil.charting.data.LineDataSet)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)17 BarEntry (com.github.mikephil.charting.data.BarEntry)13 ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)10 Path (android.graphics.Path)7 PieEntry (com.github.mikephil.charting.data.PieEntry)7 IOException (java.io.IOException)6 PointF (android.graphics.PointF)5 CandleEntry (com.github.mikephil.charting.data.CandleEntry)5 PieDataSet (com.github.mikephil.charting.data.PieDataSet)5 ScatterData (com.github.mikephil.charting.data.ScatterData)5 Highlight (com.github.mikephil.charting.highlight.Highlight)5 Transformer (com.github.mikephil.charting.utils.Transformer)5 Test (org.junit.Test)5 MPPointF (com.github.mikephil.charting.utils.MPPointF)4 SuppressLint (android.annotation.SuppressLint)3