Search in sources :

Example 61 with Entry

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

the class CombinedChartActivity method generateLineData.

private LineData generateLineData() {
    LineData d = new LineData();
    ArrayList<Entry> entries = new ArrayList<Entry>();
    for (int index = 0; index < itemcount; index++) entries.add(new Entry(index + 0.5f, getRandom(15, 5)));
    LineDataSet set = new LineDataSet(entries, "Line DataSet");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleRadius(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    d.addDataSet(set);
    return d;
}
Also used : LineData(com.github.mikephil.charting.data.LineData) CandleEntry(com.github.mikephil.charting.data.CandleEntry) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 62 with Entry

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

the class CubicLineChartActivity 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) + 20;
        // ((mult *
        // 0.1) / 10);
        yVals.add(new Entry(i, val));
    }
    LineDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(yVals, "DataSet 1");
        set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        set1.setCubicIntensity(0.2f);
        //set1.setDrawFilled(true);
        set1.setDrawCircles(false);
        set1.setLineWidth(1.8f);
        set1.setCircleRadius(4f);
        set1.setCircleColor(Color.WHITE);
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setColor(Color.WHITE);
        set1.setFillColor(Color.WHITE);
        set1.setFillAlpha(100);
        set1.setDrawHorizontalHighlightIndicator(false);
        set1.setFillFormatter(new IFillFormatter() {

            @Override
            public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
                return -10;
            }
        });
        // create a data object with the datasets
        LineData data = new LineData(set1);
        data.setValueTypeface(mTfLight);
        data.setValueTextSize(9f);
        data.setDrawValues(false);
        // 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) LineDataProvider(com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider) IFillFormatter(com.github.mikephil.charting.formatter.IFillFormatter)

Example 63 with Entry

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

the class DynamicalAddingActivity method addEntry.

private void addEntry() {
    LineData data = mChart.getData();
    ILineDataSet set = data.getDataSetByIndex(0);
    if (set == null) {
        set = createSet();
        data.addDataSet(set);
    }
    // choose a random dataSet
    int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
    float yValue = (float) (Math.random() * 10) + 50f;
    data.addEntry(new Entry(data.getDataSetByIndex(randomDataSetIndex).getEntryCount(), yValue), randomDataSetIndex);
    data.notifyDataChanged();
    // let the chart know it's data has changed
    mChart.notifyDataSetChanged();
    mChart.setVisibleXRangeMaximum(6);
    //mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
    //            
    //            // this automatically refreshes the chart (calls invalidate())
    mChart.moveViewTo(data.getEntryCount() - 7, 50f, AxisDependency.LEFT);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet)

Example 64 with Entry

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

the class DynamicalAddingActivity method removeLastEntry.

private void removeLastEntry() {
    LineData data = mChart.getData();
    if (data != null) {
        ILineDataSet set = data.getDataSetByIndex(0);
        if (set != null) {
            Entry e = set.getEntryForXValue(set.getEntryCount() - 1, Float.NaN);
            data.removeEntry(e, 0);
            // or remove by index
            // mData.removeEntryByXValue(xIndex, dataSetIndex);
            data.notifyDataChanged();
            mChart.notifyDataSetChanged();
            mChart.invalidate();
        }
    }
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet)

Example 65 with Entry

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

the class FilledLineActivity method setData.

private void setData(int count, float range) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        // + (float)
        float val = (float) (Math.random() * range) + 50;
        // ((mult *
        // 0.1) / 10);
        yVals1.add(new Entry(i, val));
    }
    ArrayList<Entry> yVals2 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        // + (float)
        float val = (float) (Math.random() * range) + 450;
        // ((mult *
        // 0.1) / 10);
        yVals2.add(new Entry(i, val));
    }
    LineDataSet set1, set2;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
        set1.setValues(yVals1);
        set2.setValues(yVals2);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(yVals1, "DataSet 1");
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);
        set1.setColor(Color.rgb(255, 241, 46));
        set1.setDrawCircles(false);
        set1.setLineWidth(2f);
        set1.setCircleRadius(3f);
        set1.setFillAlpha(255);
        set1.setDrawFilled(true);
        set1.setFillColor(Color.WHITE);
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setDrawCircleHole(false);
        set1.setFillFormatter(new IFillFormatter() {

            @Override
            public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
                return mChart.getAxisLeft().getAxisMinimum();
            }
        });
        // create a dataset and give it a type
        set2 = new LineDataSet(yVals2, "DataSet 2");
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);
        set2.setColor(Color.rgb(255, 241, 46));
        set2.setDrawCircles(false);
        set2.setLineWidth(2f);
        set2.setCircleRadius(3f);
        set2.setFillAlpha(255);
        set2.setDrawFilled(true);
        set2.setFillColor(Color.WHITE);
        set2.setDrawCircleHole(false);
        set2.setHighLightColor(Color.rgb(244, 117, 117));
        set2.setFillFormatter(new IFillFormatter() {

            @Override
            public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
                return mChart.getAxisLeft().getAxisMaximum();
            }
        });
        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        // add the datasets
        dataSets.add(set1);
        dataSets.add(set2);
        // create a data object with the datasets
        LineData data = new LineData(dataSets);
        data.setDrawValues(false);
        // 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) LineDataProvider(com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider) IFillFormatter(com.github.mikephil.charting.formatter.IFillFormatter)

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