Search in sources :

Example 16 with LineDataSet

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

the class LineChart method drawAdditional.

/**
     * draws the circle value indicators
     */
@Override
protected void drawAdditional() {
    mRenderPaint.setStyle(Paint.Style.FILL);
    ArrayList<LineDataSet> dataSets = mData.getDataSets();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        LineDataSet dataSet = dataSets.get(i);
        // if drawing circles is enabled for this dataset
        if (dataSet.isDrawCirclesEnabled()) {
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            for (int j = 0; j < positions.length * mPhaseX; j += 2) {
                // Set the color for the currently drawn value. If the index
                // is
                // out of bounds, reuse colors.
                mRenderPaint.setColor(dataSet.getCircleColor(j / 2));
                if (isOffContentRight(positions[j]))
                    break;
                // bounds
                if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1]))
                    continue;
                mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize(), mRenderPaint);
                mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize() / 2f, mCirclePaintInner);
            }
        }
    // else do nothing
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineDataSet(com.github.mikephil.charting.data.LineDataSet) Paint(android.graphics.Paint)

Example 17 with LineDataSet

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

the class LineChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) {
        ArrayList<LineDataSet> dataSets = mData.getDataSets();
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            LineDataSet dataSet = dataSets.get(i);
            // make sure the values do not interfear with the circles
            int valOffset = (int) (dataSet.getCircleSize() * 1.75f);
            if (!dataSet.isDrawCirclesEnabled())
                valOffset = valOffset / 2;
            ArrayList<Entry> entries = dataSet.getYVals();
            float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY);
            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] - valOffset, mValuePaint);
                } else {
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - valOffset, mValuePaint);
                }
            }
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineDataSet(com.github.mikephil.charting.data.LineDataSet) Paint(android.graphics.Paint)

Example 18 with LineDataSet

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

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

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

the class DynamicalAddingActivity method createSet.

private LineDataSet createSet() {
    LineDataSet set = new LineDataSet(null, "DataSet 1");
    set.setLineWidth(2.5f);
    set.setCircleRadius(4.5f);
    set.setColor(Color.rgb(240, 99, 99));
    set.setCircleColor(Color.rgb(240, 99, 99));
    set.setHighLightColor(Color.rgb(190, 190, 190));
    set.setAxisDependency(AxisDependency.LEFT);
    set.setValueTextSize(10f);
    return set;
}
Also used : ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet)

Aggregations

LineDataSet (com.github.mikephil.charting.data.LineDataSet)32 LineData (com.github.mikephil.charting.data.LineData)23 Entry (com.github.mikephil.charting.data.Entry)19 ArrayList (java.util.ArrayList)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)15 Paint (android.graphics.Paint)6 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 Legend (com.github.mikephil.charting.components.Legend)3 BarEntry (com.github.mikephil.charting.data.BarEntry)3 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 DashPathEffect (android.graphics.DashPathEffect)1 Drawable (android.graphics.drawable.Drawable)1 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)1 CandleEntry (com.github.mikephil.charting.data.CandleEntry)1 CombinedData (com.github.mikephil.charting.data.CombinedData)1