1
votes

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!

3

3 Answers

0
votes

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

0
votes

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));
            }
0
votes

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.