I am trying to make a good looking line chart iwht MPAndroidChart, but I am having some problems.
Here is what I got now
and here is the code for it
public void createGraph() {
chart.setTouchEnabled(false);
chart.setDragEnabled(false);
chart.setHighlightEnabled(false);
chart.setDrawYLabels(true);
chart.setDrawXLabels(true);
chart.animateXY(2000, 2000);
chart.setDrawBorder(true);
chart.setPadding(30, 30, 30, 30);
setData();
}
private void setData() {
String[] stages = { "Stage1", "Stage2", "Stage3", "Stage4" };
ArrayList<Entry> yVals = new ArrayList<Entry>();
yVals.add(new Entry(0.0f, 0));
yVals.add(new Entry(Float.parseFloat(nicotineTwo), 1));
yVals.add(new Entry(Float.parseFloat(nicotineThree), 2));
yVals.add(new Entry(Float.parseFloat(nicotineFour), 3));
LineDataSet set1 = new LineDataSet(yVals, "");
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(1f);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1);
LineData data = new LineData(stages, dataSets);
chart.setData(data);
}
What I need is:
Please help me, this library is realy confusing me
chart.getLegend().setEnabled(false)
to disable it.chart.setDescriptionTextSize(...)
to customize its size.There are two possible solutions. You can either add more margin via .xml, or call
XAxis x = chart.getXAxis();
x.setAvoidFirstLastClipping(true);
data.setValueTextSize(...)
. For customly formatting values inside the chart, check out the ValueFormatter
interface the library provides.ValueFormatter
interface. e.g. if(value == 0) return "";
yAxis.setAxisMaxValue(...)
& yAxis.setAxisMinValue(...)
.Here is the full documentation.