使用MPAndroid图表绘制立方折线图
Drawing a cubic line chart using MPAndroid chart
我正在尝试绘制这样的立方线图:
使用 MPAndroid 图表库。
我可以画线,但不能画 X 轴和线之间的填充,如图所示。
浏览了图书馆和许多 SO 问题。
我想你需要这个:
LineDataSet dataset = new LineDataSet(vals, null);
dataset.setDrawFilled(true);
Set to true if the DataSet
should be drawn filled (surface), and not just as a line, disabling this will give great performance boost! default: false
您还可以控制透明度:
sets the alpha value (transparency) that is used for filling the line surface (0-255), default: 85
和颜色:
sets the color that is used for filling the line surface
要删除水平网格线:
chart.getXAxis().setDrawGridLines(false);
对于立方线:
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
填充线下区域,禁用显示值:
dataSet.setDrawFilled(true);
dataSet.setDrawValues(false);
设置填充颜色和线条颜色:
dataSet.setFillColor(ContextCompat.getColor(contex,R.color.pale_green));
dataSet.setColor(ContextCompat.getColor(contex,R.color.pale_green));
禁用透明度(值范围 0-255)并禁用在主图表线上绘制圆圈:
dataSet.setFillAlpha(255);
dataSet.setDrawCircles(false);
结果:
编辑1:
要禁用图例并隐藏描述:
chart.getDescription().setText("");
chart.getLegend().setEnabled(false);
和:
<color name="pale_green">#6BF3AD</color>
edit2:禁用右轴:
chart.getAxisRight().setEnabled(false);
edit3:差点忘了最后一件事:
chart.getAxisLeft().setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return String.format("%.2f $",value);
}
});
我正在尝试绘制这样的立方线图:
使用 MPAndroid 图表库。
我可以画线,但不能画 X 轴和线之间的填充,如图所示。
浏览了图书馆和许多 SO 问题。
我想你需要这个:
LineDataSet dataset = new LineDataSet(vals, null);
dataset.setDrawFilled(true);
Set to true if the
DataSet
should be drawn filled (surface), and not just as a line, disabling this will give great performance boost! default:false
您还可以控制透明度:
sets the alpha value (transparency) that is used for filling the line surface (0-255), default: 85
和颜色:
sets the color that is used for filling the line surface
要删除水平网格线:
chart.getXAxis().setDrawGridLines(false);
对于立方线:
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
填充线下区域,禁用显示值:
dataSet.setDrawFilled(true); dataSet.setDrawValues(false);
设置填充颜色和线条颜色:
dataSet.setFillColor(ContextCompat.getColor(contex,R.color.pale_green)); dataSet.setColor(ContextCompat.getColor(contex,R.color.pale_green));
禁用透明度(值范围 0-255)并禁用在主图表线上绘制圆圈:
dataSet.setFillAlpha(255); dataSet.setDrawCircles(false);
结果:
编辑1: 要禁用图例并隐藏描述:
chart.getDescription().setText("");
chart.getLegend().setEnabled(false);
和:
<color name="pale_green">#6BF3AD</color>
edit2:禁用右轴:
chart.getAxisRight().setEnabled(false);
edit3:差点忘了最后一件事:
chart.getAxisLeft().setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return String.format("%.2f $",value);
}
});