36

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");
Ricky Dev
  • 45
  • 1
  • 6
rafaelasguerra
  • 2,685
  • 5
  • 24
  • 56

7 Answers7

55

update answer

chart.setNoDataText("Description that you want");
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
13

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(...);
... 
David Miguel
  • 12,154
  • 3
  • 66
  • 68
9

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

Sundeep Badhotiya
  • 810
  • 2
  • 9
  • 14
6
@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");
Puppi
  • 81
  • 2
  • 2
3

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

@Override
    public void setDataMessagePieChart() {
        pieChart.setNoDataText("... your message ...");
        pieChart.invalidate();
    }
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
tony esna
  • 41
  • 1
0

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");
herrzura
  • 1
  • 4
0

If setNoDataText is not working, you have to set it (and after that run an invalidate()) when you are initializing the chart. Don't do it when you are right away to set the data.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30491835) – Nur Dec 03 '21 at 08:38