I was trying to draw a cubic line graph such as this:
using the MPAndroid chart library.
I am able to draw the line but not the fill between the X Axis and the line as shown in the picture.
Have gone through library and many SO questions.
I was trying to draw a cubic line graph such as this:
using the MPAndroid chart library.
I am able to draw the line but not the fill between the X Axis and the line as shown in the picture.
Have gone through library and many SO questions.
I think you need this:
LineDataSet dataset = new LineDataSet(vals, null);
dataset.setDrawFilled(true);
Set to true if the
DataSetshould be drawn filled (surface), and not just as a line, disabling this will give great performance boost! default:false
You can also control the transparency:
sets the alpha value (transparency) that is used for filling the line surface (0-255), default: 85
And color:
sets the color that is used for filling the line surface
To remove horizontal grid lines:
chart.getXAxis().setDrawGridLines(false);
For cubic lines:
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
To Fill area below line, disable displayed values:
dataSet.setDrawFilled(true);
dataSet.setDrawValues(false);
Set fill color and line color:
dataSet.setFillColor(ContextCompat.getColor(contex,R.color.pale_green));
dataSet.setColor(ContextCompat.getColor(contex,R.color.pale_green));
Disable transparency (values range 0-255) and disable drawing circles on the main chart line:
dataSet.setFillAlpha(255);
dataSet.setDrawCircles(false);
edit1: To disable legend and hide description:
chart.getDescription().setText("");
chart.getLegend().setEnabled(false);
and:
<color name="pale_green">#6BF3AD</color>
edit2: To disable right axis:
chart.getAxisRight().setEnabled(false);
edit3: Nearly forgot the last thing:
chart.getAxisLeft().setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return String.format("%.2f $",value);
}
});