在未填充图表的情况下,有任何方法可以更改消息"没有可用的图表数据" ?
修改:找到答案
chart.setNoDataText("Description that you want");
答案 0 :(得分:33)
更新回答
chart.setNoDataText("Description that you want");
答案 1 :(得分:9)
如果您还想自定义外观&感觉,你可以通过Paint
对象:
mChart.setNoDataText("Description that you want");
Paint p = mChart.getPaint(Chart.PAINT_INFO);
p.setTextSize(...);
p.setColor(...);
p.setTypeface(...);
...
答案 2 :(得分:3)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firestore__eintraege__heute);
mChart = findViewById(R.id.chartZuckerHeute);
mChart.setNoDataText("PUT IT HERE ON TOP; WORKED FOR ME");
答案 3 :(得分:3)
正确答案在这里:
pie_chart.setNoDataText("No Data Available");
val paint:Paint = pie_chart.getPaint(Chart.PAINT_INFO)
paint.textSize = 40f
pie_chart.invalidate()
您还设置了其他属性,例如文本颜色,文本字体等
答案 4 :(得分:0)
您需要将pieChart.invalidate()
放在setNoDataText()
之后:
@Override
public void setDataMessagePieChart() {
pieChart.setNoDataText("... your message ...");
pieChart.invalidate();
}
答案 5 :(得分:0)
这是一个有点旧的线程,但是我遇到了同样的问题,因此我的解决方案是在图表初始化后立即设置nodatatext:
PieChart pieChart = findViewById(R.id.chart) //in case of fragment view.findViewById(R.id.chart)
pieChart.setNoDataText("Loading");