Search in sources :

Example 11 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityLine method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setLabel("Realm LineDataSet");
    set.setDrawCircleHole(false);
    set.setColor(ColorTemplate.rgb("#FF5722"));
    set.setCircleColor(ColorTemplate.rgb("#FF5722"));
    set.setLineWidth(1.8f);
    set.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    LineData data = new LineData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ArrayList(java.util.ArrayList) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)

Example 12 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project MPAndroidChart by PhilJay.

the class SimpleFragment method generateLineData.

protected LineData generateLineData() {
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function");
    LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "cosine.txt"), "Cosine function");
    ds1.setLineWidth(2f);
    ds2.setLineWidth(2f);
    ds1.setDrawCircles(false);
    ds2.setDrawCircles(false);
    ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    // load DataSets from textfiles in assets folders
    sets.add(ds1);
    sets.add(ds2);
    LineData d = new LineData(sets);
    d.setValueTypeface(tf);
    return d;
}
Also used : 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 13 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet 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 14 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project MPAndroidChart by PhilJay.

the class LineChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    LineData lineData = mChart.getLineData();
    for (Highlight high : indices) {
        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        Entry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator.getPhaseY());
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 15 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project MPAndroidChart by PhilJay.

the class LineChartRenderer method drawCircles.

protected void drawCircles(Canvas c) {
    mRenderPaint.setStyle(Paint.Style.FILL);
    float phaseY = mAnimator.getPhaseY();
    mCirclesBuffer[0] = 0;
    mCirclesBuffer[1] = 0;
    List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();
    for (int i = 0; i < dataSets.size(); i++) {
        ILineDataSet dataSet = dataSets.get(i);
        if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() || dataSet.getEntryCount() == 0)
            continue;
        mCirclePaintInner.setColor(dataSet.getCircleHoleColor());
        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
        mXBounds.set(mChart, dataSet);
        float circleRadius = dataSet.getCircleRadius();
        float circleHoleRadius = dataSet.getCircleHoleRadius();
        boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f;
        boolean drawTransparentCircleHole = drawCircleHole && dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;
        DataSetImageCache imageCache;
        if (mImageCaches.containsKey(dataSet)) {
            imageCache = mImageCaches.get(dataSet);
        } else {
            imageCache = new DataSetImageCache();
            mImageCaches.put(dataSet, imageCache);
        }
        boolean changeRequired = imageCache.init(dataSet);
        // only fill the cache with new bitmaps if a change is required
        if (changeRequired) {
            imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole);
        }
        int boundsRangeCount = mXBounds.range + mXBounds.min;
        for (int j = mXBounds.min; j <= boundsRangeCount; j++) {
            Entry e = dataSet.getEntryForIndex(j);
            if (e == null)
                break;
            mCirclesBuffer[0] = e.getX();
            mCirclesBuffer[1] = e.getY() * phaseY;
            trans.pointValuesToPixel(mCirclesBuffer);
            if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0]))
                break;
            if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1]))
                continue;
            Bitmap circleBitmap = imageCache.getBitmap(j);
            if (circleBitmap != null) {
                c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null);
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Bitmap(android.graphics.Bitmap) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Transformer(com.github.mikephil.charting.utils.Transformer) Paint(android.graphics.Paint)

Aggregations

ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)17 LineData (com.github.mikephil.charting.data.LineData)15 Entry (com.github.mikephil.charting.data.Entry)12 ArrayList (java.util.ArrayList)10 LineDataSet (com.github.mikephil.charting.data.LineDataSet)8 Paint (android.graphics.Paint)4 Bitmap (android.graphics.Bitmap)2 Drawable (android.graphics.drawable.Drawable)2 RealmLineDataSet (com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)2 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 Transformer (com.github.mikephil.charting.utils.Transformer)2 Canvas (android.graphics.Canvas)1 DashPathEffect (android.graphics.DashPathEffect)1 AxisBase (com.github.mikephil.charting.components.AxisBase)1 Legend (com.github.mikephil.charting.components.Legend)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 RealmBarDataSet (com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet)1