Search in sources :

Example 6 with LineData

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

the class LineChartTime method setData.

private void setData(int count, float range) {
    // now in hours
    long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());
    ArrayList<Entry> values = new ArrayList<Entry>();
    float from = now;
    // count = hours
    float to = now + count;
    // increment by 1 hour
    for (float x = from; x < to; x++) {
        float y = getRandom(range, 50);
        // add one entry per hour
        values.add(new Entry(x, y));
    }
    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(values, "DataSet 1");
    set1.setAxisDependency(AxisDependency.LEFT);
    set1.setColor(ColorTemplate.getHoloBlue());
    set1.setValueTextColor(ColorTemplate.getHoloBlue());
    set1.setLineWidth(1.5f);
    set1.setDrawCircles(false);
    set1.setDrawValues(false);
    set1.setFillAlpha(65);
    set1.setFillColor(ColorTemplate.getHoloBlue());
    set1.setHighLightColor(Color.rgb(244, 117, 117));
    set1.setDrawCircleHole(false);
    // create a data object with the datasets
    LineData data = new LineData(set1);
    data.setValueTextColor(Color.WHITE);
    data.setValueTextSize(9f);
    // 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) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 7 with LineData

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

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

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

the class DynamicalAddingActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.actionAddEntry:
            addEntry();
            Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show();
            break;
        case R.id.actionRemoveEntry:
            removeLastEntry();
            Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show();
            break;
        case R.id.actionAddDataSet:
            addDataSet();
            Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show();
            break;
        case R.id.actionRemoveDataSet:
            removeDataSet();
            Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show();
            break;
        case R.id.actionAddEmptyLineData:
            mChart.setData(new LineData());
            mChart.invalidate();
            Toast.makeText(this, "Empty data added!", Toast.LENGTH_SHORT).show();
            break;
        case R.id.actionClear:
            mChart.clear();
            Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show();
            break;
    }
    return true;
}
Also used : LineData(com.github.mikephil.charting.data.LineData)

Example 10 with LineData

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

the class InvertedLineChartActivity method setData.

private void setData(int count, float range) {
    ArrayList<Entry> entries = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float xVal = (float) (Math.random() * range);
        float yVal = (float) (Math.random() * range);
        entries.add(new Entry(xVal, yVal));
    }
    // sort by x-value
    Collections.sort(entries, new EntryXComparator());
    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(entries, "DataSet 1");
    set1.setLineWidth(1.5f);
    set1.setCircleRadius(4f);
    // create a data object with the datasets
    LineData data = new LineData(set1);
    // set data
    mChart.setData(data);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) EntryXComparator(com.github.mikephil.charting.utils.EntryXComparator) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Aggregations

LineData (com.github.mikephil.charting.data.LineData)37 LineDataSet (com.github.mikephil.charting.data.LineDataSet)22 Entry (com.github.mikephil.charting.data.Entry)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)19 ArrayList (java.util.ArrayList)19 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 BarEntry (com.github.mikephil.charting.data.BarEntry)3 Legend (com.github.mikephil.charting.components.Legend)2 BarData (com.github.mikephil.charting.data.BarData)2 RealmLineDataSet (com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 DashPathEffect (android.graphics.DashPathEffect)1 Paint (android.graphics.Paint)1