com.github.mikephil.charting.interfaces.datasets.IScatterDataSet Java Examples

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.IScatterDataSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Transformer.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data,
                                                float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);

        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #2
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {

        ArrayList<IScatterDataSet> sets = new ArrayList<>();

        ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();

        for(int i = 0; i < dataSets; i++) {

            ArrayList<Entry> entries = new ArrayList<>();

            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;
    }
 
Example #3
Source File: ChevronDownShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                 float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);
}
 
Example #4
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {
    
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    
    ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
    
    for(int i = 0; i < dataSets; i++) {
       
        ArrayList<Entry> entries = new ArrayList<Entry>();
        
        for(int j = 0; j < count; j++) {        
            entries.add(new Entry((float) (Math.random() * range) + range / 4, j));
        }
        
        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(ChartData.generateXVals(0, count), sets);
    d.setValueTypeface(tf);
    return d;
}
 
Example #5
Source File: ChevronUpShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);

}
 
Example #6
Source File: Transformer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data,
                                                float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);

        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #7
Source File: RealmDatabaseActivityScatter.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);

        RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "value", "xIndex");
        set.setLabel("Realm ScatterDataSet");
        set.setScatterShapeSize(9f);
        set.setColor(ColorTemplate.rgb("#CDDC39"));
        set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);

        ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
        dataSets.add(set); // add the dataset

        // create a data object with the dataset list
        RealmScatterData data = new RealmScatterData(result, "xValue", dataSets);
        styleData(data);

        // set data
        mChart.setData(data);
        mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    }
 
Example #8
Source File: ChevronDownShapeRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);
}
 
Example #9
Source File: ChevronUpShapeRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);

}
 
Example #10
Source File: CrossShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY,
            posX + shapeHalf,
            posY,
            renderPaint);
    c.drawLine(
            posX,
            posY - shapeHalf,
            posX,
            posY + shapeHalf,
            renderPaint);

}
 
Example #11
Source File: CrossShapeRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY,
            posX + shapeHalf,
            posY,
            renderPaint);
    c.drawLine(
            posX,
            posY - shapeHalf,
            posX,
            posY + shapeHalf,
            renderPaint);

}
 
Example #12
Source File: CrossShapeRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY,
            posX + shapeHalf,
            posY,
            renderPaint);
    c.drawLine(
            posX,
            posY - shapeHalf,
            posX,
            posY + shapeHalf,
            renderPaint);

}
 
Example #13
Source File: ChevronUpShapeRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY - (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);

}
 
Example #14
Source File: XShapeRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY - shapeHalf,
            posX + shapeHalf,
            posY + shapeHalf,
            renderPaint);
    c.drawLine(
            posX + shapeHalf,
            posY - shapeHalf,
            posX - shapeHalf,
            posY + shapeHalf,
            renderPaint);

}
 
Example #15
Source File: ChevronDownShapeRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                 float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);
}
 
Example #16
Source File: XShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY - shapeHalf,
            posX + shapeHalf,
            posY + shapeHalf,
            renderPaint);
    c.drawLine(
            posX + shapeHalf,
            posY - shapeHalf,
            posX - shapeHalf,
            posY + shapeHalf,
            renderPaint);

}
 
Example #17
Source File: ScatterData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Returns the maximum shape-size across all DataSets.
 *
 * @return
 */
public float getGreatestShapeSize() {

    float max = 0f;

    for (IScatterDataSet set : mDataSets) {
        float size = set.getScatterShapeSize();

        if (size > max)
            max = size;
    }

    return max;
}
 
Example #18
Source File: ScatterData.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Returns the maximum shape-size across all DataSets.
 *
 * @return
 */
public float getGreatestShapeSize() {

    float max = 0f;

    for (IScatterDataSet set : mDataSets) {
        float size = set.getScatterShapeSize();

        if (size > max)
            max = size;
    }

    return max;
}
 
Example #19
Source File: ScatterData.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maximum shape-size across all DataSets.
 * 
 * @return
 */
public float getGreatestShapeSize() {

    float max = 0f;

    for (IScatterDataSet set : mDataSets) {
        float size = set.getScatterShapeSize();

        if (size > max)
            max = size;
    }

    return max;
}
 
Example #20
Source File: Transformer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX,
                                                float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesScatter.length != count) {
        valuePointsForGenerateTransformedValuesScatter = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesScatter;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #21
Source File: ScatterChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    ScatterData scatterData = mChart.getScatterData();

    for (IScatterDataSet set : scatterData.getDataSets()) {

        if (set.isVisible())
            drawDataSet(c, set);
    }
}
 
Example #22
Source File: XShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
        c.drawLine(
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
    }

}
 
Example #23
Source File: Transformer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX,
                                                float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesScatter.length != count) {
        valuePointsForGenerateTransformedValuesScatter = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesScatter;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #24
Source File: ScatterChartRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    ScatterData scatterData = mChart.getScatterData();

    for (IScatterDataSet set : scatterData.getDataSets()) {

        if (set.isVisible())
            drawDataSet(c, set);
    }
}
 
Example #25
Source File: ScatterChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    ScatterData scatterData = mChart.getScatterData();

    for (IScatterDataSet set : scatterData.getDataSets()) {

        if (set.isVisible())
            drawDataSet(c, set);
    }
}
 
Example #26
Source File: ChevronUpShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] - (2 * shapeHalf),
                buffer.buffer[i] + (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] - (2 * shapeHalf),
                buffer.buffer[i] - (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);
    }

}
 
Example #27
Source File: ScatterChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    ScatterData scatterData = mChart.getScatterData();

    mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()];

    for (int i = 0; i < mScatterBuffers.length; i++) {
        IScatterDataSet set = scatterData.getDataSetByIndex(i);
        mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2);
    }
}
 
Example #28
Source File: ChevronDownShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] + (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] - (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);
    }

}
 
Example #29
Source File: ScatterData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maximum shape-size across all DataSets.
 *
 * @return
 */
public float getGreatestShapeSize() {

    float max = 0f;

    for (IScatterDataSet set : mDataSets) {
        float size = set.getScatterShapeSize();

        if (size > max)
            max = size;
    }

    return max;
}
 
Example #30
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    ScatterData scatterData = mChart.getScatterData();

    for (IScatterDataSet set : scatterData.getDataSets()) {

        if (set.isVisible())
            drawDataSet(c, set);
    }
}