Search in sources :

Example 1 with IScatterDataSet

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

the class ScatterChartRenderer method drawValues.

@Override
public void drawValues(Canvas c) {
    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {
        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();
        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {
            IScatterDataSet dataSet = dataSets.get(i);
            if (!shouldDrawValues(dataSet))
                continue;
            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);
            mXBounds.set(mChart, dataSet);
            float[] positions = mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
            float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
            for (int j = 0; j < positions.length; j += 2) {
                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;
                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;
                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }
                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
                    Drawable icon = entry.getIcon();
                    Utils.drawImage(c, icon, (int) (positions[j] + iconsOffset.x), (int) (positions[j + 1] + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
                }
            }
            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) MPPointF(com.github.mikephil.charting.utils.MPPointF) Drawable(android.graphics.drawable.Drawable)

Example 2 with IScatterDataSet

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

the class RealmDatabaseActivityScatter method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
    set.setLabel("Realm ScatterDataSet");
    set.setScatterShapeSize(9f);
    set.setColor(ColorTemplate.rgb("#CDDC39"));
    set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    ScatterData data = new ScatterData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) ArrayList(java.util.ArrayList) RealmScatterDataSet(com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData) ScatterData(com.github.mikephil.charting.data.ScatterData)

Example 3 with IScatterDataSet

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

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

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

the class ScatterChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    ScatterData scatterData = mChart.getScatterData();
    for (Highlight high : indices) {
        IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        final 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 : Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) IScatterDataSet(com.github.mikephil.charting.interfaces.datasets.IScatterDataSet) MPPointD(com.github.mikephil.charting.utils.MPPointD) ScatterData(com.github.mikephil.charting.data.ScatterData)

Aggregations

IScatterDataSet (com.github.mikephil.charting.interfaces.datasets.IScatterDataSet)5 Entry (com.github.mikephil.charting.data.Entry)4 ScatterData (com.github.mikephil.charting.data.ScatterData)4 ArrayList (java.util.ArrayList)3 ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)2 Drawable (android.graphics.drawable.Drawable)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 RealmScatterDataSet (com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 MPPointD (com.github.mikephil.charting.utils.MPPointD)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1 CustomScatterShapeRenderer (com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer)1 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)1