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);
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations