29
votes

Is there any way to change the message "No chart data available" when the chart is not populated?

Edit: Found the answer

chart.setNoDataText("Description that you want");
6
Author found the answer to the question. - Philipp Jahoda
why you dont paste it as answer ? - Mina Fawzy

6 Answers

51
votes

update answer

chart.setNoDataText("Description that you want");
10
votes

If you also want to customize look & feel, you can do it through Paint object:

mChart.setNoDataText("Description that you want");
Paint p = mChart.getPaint(Chart.PAINT_INFO);
p.setTextSize(...);
p.setColor(...);
p.setTypeface(...);
... 
6
votes

The Correct answer is here:

 pie_chart.setNoDataText("No Data Available");
 val paint:Paint =  pie_chart.getPaint(Chart.PAINT_INFO)
 paint.textSize = 40f
 pie_chart.invalidate()

You also set other properties like text color, text typeface etc

4
votes
@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");
1
votes

You need put pieChart.invalidate() after setNoDataText():

@Override
    public void setDataMessagePieChart() {
        pieChart.setNoDataText("... your message ...");
        pieChart.invalidate();
    }
0
votes

It's a little bit old thread, but I had the same issue so my solution was to set nodatatext immediately after the initialization of a chart:

PieChart pieChart = findViewById(R.id.chart) //in case of fragment view.findViewById(R.id.chart)
pieChart.setNoDataText("Loading");