Remove “No Chart Data” from MPAndroidChart and add my own message

I am using the MPAndroidChart Library to display a chart. An empty view for a data data chart shows "No chart data available":

a chart saying "no chart data avalable"

I also need to change this message. But it does not work to change this. I used these lines of code:

mChart.setNoDataText("No chart");
mChart.invalidate();
+4
source share
4 answers
pieChart.setNoDataText();

use it and u will get the desired text also, if you need some descriptive text you can use

pieChart.setNoDataTextDescription();
+3
source

Have you added LineDataSet?

LineData xData = mChart.getData();
ILineDataSet x = xData.getDataSetByIndex(0);
x = createXSet();
xData.addDataSet(x);

xData.addEntry(new Entry(5f, 21, 0);

xData.notifyDataChanged();

mChart.notifyDataSetChanged();
mChart.setVisibleXRangeMaximum(30);
mChart.moveViewToX(xData.getEntryCount());


private LineDataSet createXSet(boolean drawPoints) {

    LineDataSet set = new LineDataSet(null, "x");
    set.setColor(Color.GREEN);
    set.setLineWidth(2f);
    set.setCircleRadius(2f);
    set.setCircleColor(Color.WHITE);
    set.setFillAlpha(65);
    set.setFillColor(Color.GREEN);
    set.setHighLightColor(Color.rgb(244, 117, 117));
    set.setValueTextColor(Color.WHITE);
    set.setValueTextSize(9f);
    set.setDrawValues(false);
    return set;
}
0
source

:

chart.setNoDataText("Your description");

Paint:

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

: MPAndroidChart - " "

0
source

Make the chart invisible until the data is filled. This should solve the problem.

-1
source

Source: https://habr.com/ru/post/1656902/


All Articles