1

I am using MPAndroidChart to draw some charts on my Android application and I would like to change the default message that appears when the data is not available.

I am using a CombinedChart and a BarChart and in none of them I am able to change the text when data is not available.

I know that there are few questions on Stackoverflow related with this theme. For example:

but all of them make reference to one or more of these methods:

.setDescription("");
.setNoDataTextDescription("Custom message.");
.setNoDataTextDescription("Custom message");
.setNoDataText("Custom message");

Any of them worked for me.

My snippet of code in which I try to change the text is the following:

combinedChart.setDescription(null);
combinedChart.setNoDataText("No data");

combinedChart.setData(data);
combinedChart.animateXY(2500,2500);

How can I provide a different text message to the user when data is not available?

EDIT: I have added .invalidate method as @SudhakarRaju suggested but it also does not work. My actual code is:

combinedChart.setDescription(null);
combinedChart.setNoDataText("No data");
combinedChart.setNoDataTextDescription("No data");
combinedChart.setNoDataTextDescription("No data");

combinedChart.invalidate();
combinedChart.setData(data);
combinedChart.animateXY(2500,2500);
//I also tried to put combinedChart.invalidate(); here but it also does not work.

Thanks in advance!

Community
  • 1
  • 1
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167

3 Answers3

0

The same way above you mentioned but you have to add one extra line. combinedChart.invalidate(); This will work.

0

This code allows you to style the chart if no data:

            mChart.setNoDataText(getResources().getString(R.string.no_data_available));
            mChart.setNoDataTextColor(BaseActivity.getAppColor(R.color.black));

            // from: https://github.com/PhilJay/MPAndroidChart/issues/89
            Paint p = mChart.getPaint(Chart.PAINT_INFO);
            if (p != null) {
                p.setTextSize(getResources().getInteger(R.integer.no_data_text_size));
            }
Lee Hounshell
  • 842
  • 9
  • 10
0

Remove the combinedChart.setData(data) call.

For some reason, if you send an empty Data object that contains an empty data set, the "no data" text will not be displayed.

I had the same problem and I resolved it by simply not setting the data if it's empty, or using combinedChart.clear() for that matter.

Lucas Cabrales
  • 2,073
  • 1
  • 12
  • 21