Search in sources :

Example 1 with ILineDataSet

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

the class ListViewMultiChartActivity method generateDataLine.

/**
     * generates a random ChartData object with just one DataSet
     * 
     * @return
     */
private LineData generateDataLine(int cnt) {
    ArrayList<Entry> e1 = new ArrayList<Entry>();
    for (int i = 0; i < 12; i++) {
        e1.add(new Entry(i, (int) (Math.random() * 65) + 40));
    }
    LineDataSet d1 = new LineDataSet(e1, "New DataSet " + cnt + ", (1)");
    d1.setLineWidth(2.5f);
    d1.setCircleRadius(4.5f);
    d1.setHighLightColor(Color.rgb(244, 117, 117));
    d1.setDrawValues(false);
    ArrayList<Entry> e2 = new ArrayList<Entry>();
    for (int i = 0; i < 12; i++) {
        e2.add(new Entry(i, e1.get(i).getY() - 30));
    }
    LineDataSet d2 = new LineDataSet(e2, "New DataSet " + cnt + ", (2)");
    d2.setLineWidth(2.5f);
    d2.setCircleRadius(4.5f);
    d2.setHighLightColor(Color.rgb(244, 117, 117));
    d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setDrawValues(false);
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    sets.add(d1);
    sets.add(d2);
    LineData cd = new LineData(sets);
    return cd;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) 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 2 with ILineDataSet

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

the class RealtimeLineChartActivity method addEntry.

private void addEntry() {
    LineData data = mChart.getData();
    if (data != null) {
        ILineDataSet set = data.getDataSetByIndex(0);
        if (set == null) {
            set = createSet();
            data.addDataSet(set);
        }
        data.addEntry(new Entry(set.getEntryCount(), (float) (Math.random() * 40) + 30f), 0);
        data.notifyDataChanged();
        // let the chart know it's data has changed
        mChart.notifyDataSetChanged();
        // limit the number of visible entries
        mChart.setVisibleXRangeMaximum(120);
        // mChart.setVisibleYRange(30, AxisDependency.LEFT);
        // move to the latest entry
        mChart.moveViewToX(data.getEntryCount());
    // this automatically refreshes the chart (calls invalidate())
    // mChart.moveViewTo(data.getXValCount()-7, 55f,
    // AxisDependency.LEFT);
    }
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet)

Example 3 with ILineDataSet

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

the class RealmWikiExample method setData.

private void setData() {
    // LINE-CHART
    final RealmResults<Score> results = mRealm.where(Score.class).findAll();
    IAxisValueFormatter formatter = new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return results.get((int) value).getPlayerName();
        }
    };
    lineChart.getXAxis().setValueFormatter(formatter);
    barChart.getXAxis().setValueFormatter(formatter);
    RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
    lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    lineDataSet.setLabel("Result Scores");
    lineDataSet.setDrawCircleHole(false);
    lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    dataSets.add(lineDataSet);
    LineData lineData = new LineData(dataSets);
    styleData(lineData);
    // set data
    lineChart.setData(lineData);
    lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    // BAR-CHART
    RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
    barDataSet.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
    barDataSet.setLabel("Realm BarDataSet");
    ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
    barDataSets.add(barDataSet);
    BarData barData = new BarData(barDataSets);
    styleData(barData);
    barChart.setData(barData);
    barChart.setFitBars(true);
    barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) RealmBarDataSet(com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet)

Example 4 with ILineDataSet

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

the class SimpleFragment method getComplexity.

protected LineData getComplexity() {
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "n.txt"), "O(n)");
    LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "nlogn.txt"), "O(nlogn)");
    LineDataSet ds3 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "square.txt"), "O(n²)");
    LineDataSet ds4 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "three.txt"), "O(n³)");
    ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    ds1.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    ds1.setLineWidth(2.5f);
    ds1.setCircleRadius(3f);
    ds2.setLineWidth(2.5f);
    ds2.setCircleRadius(3f);
    ds3.setLineWidth(2.5f);
    ds3.setCircleRadius(3f);
    ds4.setLineWidth(2.5f);
    ds4.setCircleRadius(3f);
    // load DataSets from textfiles in assets folders
    sets.add(ds1);
    sets.add(ds2);
    sets.add(ds3);
    sets.add(ds4);
    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 5 with ILineDataSet

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

the class LineChartRenderer method drawValues.

@Override
public void drawValues(Canvas c) {
    if (isDrawingValuesAllowed(mChart)) {
        List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();
        for (int i = 0; i < dataSets.size(); i++) {
            ILineDataSet dataSet = dataSets.get(i);
            if (!shouldDrawValues(dataSet))
                continue;
            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);
            Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
            // make sure the values do not interfear with the circles
            int valOffset = (int) (dataSet.getCircleRadius() * 1.75f);
            if (!dataSet.isDrawCirclesEnabled())
                valOffset = valOffset / 2;
            mXBounds.set(mChart, dataSet);
            float[] positions = trans.generateTransformedValuesLine(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
            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) {
                float x = positions[j];
                float y = positions[j + 1];
                if (!mViewPortHandler.isInBoundsRight(x))
                    break;
                if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))
                    continue;
                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, x, y - valOffset, dataSet.getValueTextColor(j / 2));
                }
                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
                    Drawable icon = entry.getIcon();
                    Utils.drawImage(c, icon, (int) (x + iconsOffset.x), (int) (y + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
                }
            }
            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Transformer(com.github.mikephil.charting.utils.Transformer) MPPointF(com.github.mikephil.charting.utils.MPPointF) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint)

Aggregations

ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)16 LineData (com.github.mikephil.charting.data.LineData)14 Entry (com.github.mikephil.charting.data.Entry)11 ArrayList (java.util.ArrayList)9 LineDataSet (com.github.mikephil.charting.data.LineDataSet)7 Paint (android.graphics.Paint)3 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 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 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)1