Search in sources :

Example 6 with ScatterDataSet

use of com.github.mikephil.charting.data.ScatterDataSet in project carat by amplab.

the class ScatterChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) {
        ArrayList<ScatterDataSet> dataSets = mData.getDataSets();
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            ScatterDataSet dataSet = dataSets.get(i);
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            float shapeSize = dataSet.getScatterShapeSize();
            for (int j = 0; j < positions.length * mPhaseX; j += 2) {
                if (isOffContentRight(positions[j]))
                    break;
                if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
                    continue;
                float val = entries.get(j / 2).getVal();
                if (mDrawUnitInChart) {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - shapeSize, mValuePaint);
                } else {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - shapeSize, mValuePaint);
                }
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet)

Example 7 with ScatterDataSet

use of com.github.mikephil.charting.data.ScatterDataSet in project carat by amplab.

the class ScatterChart method drawData.

@Override
protected void drawData() {
    ArrayList<ScatterDataSet> dataSets = mData.getDataSets();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        ScatterDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        float shapeHalf = dataSet.getScatterShapeSize() / 2f;
        float[] valuePoints = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
        ScatterShape shape = dataSet.getScatterShape();
        for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) {
            if (isOffContentRight(valuePoints[j]))
                break;
            // make sure the lines don't do shitty things outside bounds
            if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1]))
                continue;
            // Set the color for the currently drawn value. If the index is
            // out of bounds, reuse colors.
            mRenderPaint.setColor(dataSet.getColor(j));
            if (shape == ScatterShape.SQUARE) {
                mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.CIRCLE) {
                mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.CROSS) {
                mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint);
                mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint);
            } else if (shape == ScatterShape.TRIANGLE) {
                // create a triangle path
                Path tri = new Path();
                tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf);
                tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf);
                tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf);
                tri.close();
                mDrawCanvas.drawPath(tri, mRenderPaint);
            } else if (shape == ScatterShape.CUSTOM) {
                Path customShape = dataSet.getCustomScatterShape();
                if (customShape == null)
                    return;
                // transform the provided custom path
                mTrans.pathValueToPixel(customShape);
                mDrawCanvas.drawPath(customShape, mRenderPaint);
            }
        }
    }
}
Also used : Path(android.graphics.Path) Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet)

Example 8 with ScatterDataSet

use of com.github.mikephil.charting.data.ScatterDataSet 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 9 with ScatterDataSet

use of com.github.mikephil.charting.data.ScatterDataSet 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 10 with ScatterDataSet

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

the class DataSetTest method testCalcMinMax.

@Test
public void testCalcMinMax() {
    List<Entry> entries = new ArrayList<Entry>();
    entries.add(new Entry(10, 10));
    entries.add(new Entry(15, 2));
    entries.add(new Entry(21, 5));
    ScatterDataSet set = new ScatterDataSet(entries, "");
    assertEquals(10f, set.getXMin(), 0.01f);
    assertEquals(21f, set.getXMax(), 0.01f);
    assertEquals(2f, set.getYMin(), 0.01f);
    assertEquals(10f, set.getYMax(), 0.01f);
    assertEquals(3, set.getEntryCount());
    set.addEntry(new Entry(25, 1));
    assertEquals(10f, set.getXMin(), 0.01f);
    assertEquals(25f, set.getXMax(), 0.01f);
    assertEquals(1f, set.getYMin(), 0.01f);
    assertEquals(10f, set.getYMax(), 0.01f);
    assertEquals(4, set.getEntryCount());
    set.removeEntry(3);
    assertEquals(10f, set.getXMin(), 0.01f);
    assertEquals(21, set.getXMax(), 0.01f);
    assertEquals(2f, set.getYMin(), 0.01f);
    assertEquals(10f, set.getYMax(), 0.01f);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ScatterDataSet (com.github.mikephil.charting.data.ScatterDataSet)11 Entry (com.github.mikephil.charting.data.Entry)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)5 ScatterData (com.github.mikephil.charting.data.ScatterData)4 BarEntry (com.github.mikephil.charting.data.BarEntry)2 IScatterDataSet (com.github.mikephil.charting.interfaces.datasets.IScatterDataSet)2 Path (android.graphics.Path)1 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 LineData (com.github.mikephil.charting.data.LineData)1 LineDataSet (com.github.mikephil.charting.data.LineDataSet)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 CustomScatterShapeRenderer (com.xxmassdeveloper.mpchartexample.custom.CustomScatterShapeRenderer)1