Search in sources :

Example 6 with LineDataSet

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

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

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

Example 9 with LineDataSet

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

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

the class ChartDataTest method testDynamicChartData.

@Test
public void testDynamicChartData() {
    List<Entry> entries1 = new ArrayList<Entry>();
    entries1.add(new Entry(10, 10));
    entries1.add(new Entry(15, -2));
    entries1.add(new Entry(21, 50));
    ScatterDataSet set1 = new ScatterDataSet(entries1, "");
    List<Entry> entries2 = new ArrayList<Entry>();
    entries2.add(new Entry(-1, 10));
    entries2.add(new Entry(10, 2));
    entries2.add(new Entry(20, 5));
    ScatterDataSet set2 = new ScatterDataSet(entries2, "");
    ScatterData data = new ScatterData(set1, set2);
    assertEquals(-2, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(50f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(6, data.getEntryCount());
    assertEquals(-1f, data.getXMin(), 0.01f);
    assertEquals(21f, data.getXMax(), 0.01f);
    assertEquals(-2f, data.getYMin(), 0.01f);
    assertEquals(50f, data.getYMax(), 0.01f);
    assertEquals(3, data.getMaxEntryCountSet().getEntryCount());
    // now add and remove values
    data.addEntry(new Entry(-10, -10), 0);
    assertEquals(set1, data.getMaxEntryCountSet());
    assertEquals(4, data.getMaxEntryCountSet().getEntryCount());
    assertEquals(-10f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(50f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-10f, data.getXMin(), 0.01f);
    assertEquals(21f, data.getXMax(), 0.01f);
    assertEquals(-10f, data.getYMin(), 0.01f);
    assertEquals(50f, data.getYMax(), 0.01f);
    data.addEntry(new Entry(-100, 100), 0);
    data.addEntry(new Entry(0, -100), 0);
    assertEquals(-100f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    // right axis will adapt left axis values if no right axis values are present
    assertEquals(-100, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    List<Entry> entries3 = new ArrayList<Entry>();
    entries3.add(new Entry(0, 200));
    entries3.add(new Entry(0, -50));
    ScatterDataSet set3 = new ScatterDataSet(entries3, "");
    set3.setAxisDependency(YAxis.AxisDependency.RIGHT);
    data.addDataSet(set3);
    assertEquals(3, data.getDataSetCount());
    assertEquals(-100f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(100f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-50f, data.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(200f, data.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    LineData lineData = new LineData();
    assertEquals(Float.MAX_VALUE, lineData.getYMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(0, lineData.getDataSetCount());
    List<Entry> lineEntries1 = new ArrayList<Entry>();
    lineEntries1.add(new Entry(10, 90));
    lineEntries1.add(new Entry(1000, 1000));
    LineDataSet lineSet1 = new LineDataSet(lineEntries1, "");
    lineData.addDataSet(lineSet1);
    assertEquals(1, lineData.getDataSetCount());
    assertEquals(2, lineSet1.getEntryCount());
    assertEquals(2, lineData.getEntryCount());
    assertEquals(10, lineData.getXMin(), 0.01f);
    assertEquals(1000f, lineData.getXMax(), 0.01f);
    assertEquals(90, lineData.getYMin(), 0.01f);
    assertEquals(1000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(1000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    List<Entry> lineEntries2 = new ArrayList<Entry>();
    lineEntries2.add(new Entry(-1000, 2000));
    lineEntries2.add(new Entry(2000, -3000));
    Entry e = new Entry(-1000, 2500);
    lineEntries2.add(e);
    LineDataSet lineSet2 = new LineDataSet(lineEntries2, "");
    lineSet2.setAxisDependency(YAxis.AxisDependency.RIGHT);
    lineData.addDataSet(lineSet2);
    assertEquals(2, lineData.getDataSetCount());
    assertEquals(3, lineSet2.getEntryCount());
    assertEquals(5, lineData.getEntryCount());
    assertEquals(-1000, lineData.getXMin(), 0.01f);
    assertEquals(2000, lineData.getXMax(), 0.01f);
    assertEquals(-3000, lineData.getYMin(), 0.01f);
    assertEquals(2500, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-3000, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2500, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertTrue(lineData.removeEntry(e, 1));
    assertEquals(-1000, lineData.getXMin(), 0.01f);
    assertEquals(2000, lineData.getXMax(), 0.01f);
    assertEquals(-3000, lineData.getYMin(), 0.01f);
    assertEquals(2000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-3000, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(2, lineData.getDataSetCount());
    assertTrue(lineData.removeDataSet(lineSet2));
    assertEquals(1, lineData.getDataSetCount());
    assertEquals(10, lineData.getXMin(), 0.01f);
    assertEquals(1000, lineData.getXMax(), 0.01f);
    assertEquals(90, lineData.getYMin(), 0.01f);
    assertEquals(1000, lineData.getYMax(), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(1000f, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(90, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(1000, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertTrue(lineData.removeDataSet(lineSet1));
    assertEquals(0, lineData.getDataSetCount());
    assertEquals(Float.MAX_VALUE, lineData.getXMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getXMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.LEFT), 0.01f);
    assertEquals(Float.MAX_VALUE, lineData.getYMin(YAxis.AxisDependency.RIGHT), 0.01f);
    assertEquals(-Float.MAX_VALUE, lineData.getYMax(YAxis.AxisDependency.RIGHT), 0.01f);
    assertFalse(lineData.removeDataSet(lineSet1));
    assertFalse(lineData.removeDataSet(lineSet2));
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ScatterDataSet(com.github.mikephil.charting.data.ScatterDataSet) ArrayList(java.util.ArrayList) ScatterData(com.github.mikephil.charting.data.ScatterData) Test(org.junit.Test)

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