Android : Need help creating a line graph with MPAndroidChart

on Sunday, February 15, 2015


I am using this library MPAndroidChart and I can't understand it much, I want to make a graph like this


enter image description here


Right now I have this


enter image description here


And this is my code:



private void setData(float range) {
ArrayList<String> xVals = new ArrayList<String>();
String[] nikotin = { "100", "75", "50", "25", "0" };
for (int i = 10; i > 0; i--) {
xVals.add((i) + "");
}
ArrayList<Entry> yVals = new ArrayList<Entry>();
for (int i = 0; i < 5; i++) {
yVals.add(new Entry(i, i));
}
// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(yVals, "Nicotine Lowered");
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(1f);
set1.setFillAlpha(65);
set1.setFillColor(Color.BLACK);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(nikotin, dataSets);
// set data
chart.setData(data);
}


What do I need to change?


0 comments:

Post a Comment