use of com.github.mikephil.charting.data.LineDataSet in project MPAndroidChart by PhilJay.
the class PerformanceLineChart 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) + 3;
// ((mult *
// 0.1) / 10);
yVals.add(new Entry(i * 0.001f, val));
}
// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
set1.setColor(Color.BLACK);
set1.setLineWidth(0.5f);
set1.setDrawValues(false);
set1.setDrawCircles(false);
set1.setMode(LineDataSet.Mode.LINEAR);
set1.setDrawFilled(false);
// create a data object with the datasets
LineData data = new LineData(set1);
// set data
mChart.setData(data);
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
l.setEnabled(false);
}
use of com.github.mikephil.charting.data.LineDataSet in project MPAndroidChart by PhilJay.
the class SimpleFragment method generateLineData.
protected LineData generateLineData() {
ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function");
LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "cosine.txt"), "Cosine function");
ds1.setLineWidth(2f);
ds2.setLineWidth(2f);
ds1.setDrawCircles(false);
ds2.setDrawCircles(false);
ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
// load DataSets from textfiles in assets folders
sets.add(ds1);
sets.add(ds2);
LineData d = new LineData(sets);
d.setValueTypeface(tf);
return d;
}
use of com.github.mikephil.charting.data.LineDataSet in project MPAndroidChart by PhilJay.
the class RealtimeLineChartActivity method createSet.
private LineDataSet createSet() {
LineDataSet set = new LineDataSet(null, "Dynamic Data");
set.setAxisDependency(AxisDependency.LEFT);
set.setColor(ColorTemplate.getHoloBlue());
set.setCircleColor(Color.WHITE);
set.setLineWidth(2f);
set.setCircleRadius(4f);
set.setFillAlpha(65);
set.setFillColor(ColorTemplate.getHoloBlue());
set.setHighLightColor(Color.rgb(244, 117, 117));
set.setValueTextColor(Color.WHITE);
set.setValueTextSize(9f);
set.setDrawValues(false);
return set;
}
use of com.github.mikephil.charting.data.LineDataSet in project MPAndroidChart by PhilJay.
the class LineChartActivity1 method setData.
private void setData(int count, float range) {
ArrayList<Entry> values = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) + 3;
values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
}
LineDataSet set1;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
set1.setValues(values);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(values, "DataSet 1");
set1.setDrawIcons(false);
// set the line to be drawn like this "- - - - - -"
set1.enableDashedLine(10f, 5f, 0f);
set1.enableDashedHighlightLine(10f, 5f, 0f);
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(1f);
set1.setCircleRadius(3f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
set1.setDrawFilled(true);
set1.setFormLineWidth(1f);
set1.setFormLineDashEffect(new DashPathEffect(new float[] { 10f, 5f }, 0f));
set1.setFormSize(15.f);
if (Utils.getSDKInt() >= 18) {
// fill drawable only supported on api level 18 and above
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
set1.setFillDrawable(drawable);
} else {
set1.setFillColor(Color.BLACK);
}
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
// add the datasets
dataSets.add(set1);
// create a data object with the datasets
LineData data = new LineData(dataSets);
// set data
mChart.setData(data);
}
}
use of com.github.mikephil.charting.data.LineDataSet in project MPAndroidChart by PhilJay.
the class LineChartActivity2 method setData.
private void setData(int count, float range) {
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
float mult = range / 2f;
float val = (float) (Math.random() * mult) + 50;
yVals1.add(new Entry(i, val));
}
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
for (int i = 0; i < count - 1; i++) {
float mult = range;
float val = (float) (Math.random() * mult) + 450;
yVals2.add(new Entry(i, val));
// if(i == 10) {
// yVals2.add(new Entry(i, val + 50));
// }
}
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
float mult = range;
float val = (float) (Math.random() * mult) + 500;
yVals3.add(new Entry(i, val));
}
LineDataSet set1, set2, set3;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
set1.setValues(yVals1);
set2.setValues(yVals2);
set3.setValues(yVals3);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create a dataset and give it a type
set1 = new LineDataSet(yVals1, "DataSet 1");
set1.setAxisDependency(AxisDependency.LEFT);
set1.setColor(ColorTemplate.getHoloBlue());
set1.setCircleColor(Color.WHITE);
set1.setLineWidth(2f);
set1.setCircleRadius(3f);
set1.setFillAlpha(65);
set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setHighLightColor(Color.rgb(244, 117, 117));
set1.setDrawCircleHole(false);
//set1.setFillFormatter(new MyFillFormatter(0f));
//set1.setDrawHorizontalHighlightIndicator(false);
//set1.setVisible(false);
//set1.setCircleHoleColor(Color.WHITE);
// create a dataset and give it a type
set2 = new LineDataSet(yVals2, "DataSet 2");
set2.setAxisDependency(AxisDependency.RIGHT);
set2.setColor(Color.RED);
set2.setCircleColor(Color.WHITE);
set2.setLineWidth(2f);
set2.setCircleRadius(3f);
set2.setFillAlpha(65);
set2.setFillColor(Color.RED);
set2.setDrawCircleHole(false);
set2.setHighLightColor(Color.rgb(244, 117, 117));
//set2.setFillFormatter(new MyFillFormatter(900f));
set3 = new LineDataSet(yVals3, "DataSet 3");
set3.setAxisDependency(AxisDependency.RIGHT);
set3.setColor(Color.YELLOW);
set3.setCircleColor(Color.WHITE);
set3.setLineWidth(2f);
set3.setCircleRadius(3f);
set3.setFillAlpha(65);
set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
set3.setDrawCircleHole(false);
set3.setHighLightColor(Color.rgb(244, 117, 117));
// create a data object with the datasets
LineData data = new LineData(set1, set2, set3);
data.setValueTextColor(Color.WHITE);
data.setValueTextSize(9f);
// set data
mChart.setData(data);
}
}
Aggregations