1

I tried to change MPAndroid Chart text of "No Chart Data available" into "Loading Data..." while the data is retrieving.I had done this.But when there is no data the chart layout should shows ," NO DATA".

I am getting the Same Text(Loading Data...) eventhough there is no data.

    protected void onDraw(Canvas canvas) {
     if (!mDataNotSet && mData==null) {
     canvas.drawText("NO DATA", getWidth() / 2, getHeight() / 3, mInfoPaint);
     return;
} 

if (mDataNotSet && mData == null || mData.getYValCount() <= 0) {
 canvas.drawText"Laoding Data...",getWidth() / 2, getHeight() / 2, mInfoPaint);

     if (!TextUtils.isEmpty(mNoDataTextDescription))
     {
     float textOffset = -mInfoPaint.ascent() + mInfoPaint.descent();
     canvas.drawText(mNoDataTextDescription, getWidth()/2,(getHeight() / 2)
                            + textOffset, mInfoPaint);
                }
     return;
            }
     if (!mOffsetsCalculated) {
       calculateOffsets();
                mOffsetsCalculated = true;
            }
        }
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Parama Sudha
  • 2,583
  • 3
  • 29
  • 48

2 Answers2

2

Use the setNoDataText method to set the message back to whatever text you want once data loading is done.

So when data load is started, run

chart.setNoDataText("Loading Data...");

After data load is done

 chart.setNoDataText("NO DATA");
Roshan
  • 3,442
  • 2
  • 14
  • 23
  • Thank you... For plotting graph I need to get a sales amount of particular shop.So I used if ...else in Fragment that I used for plotting charts if (strAmount.equals("0")) { mChart.setNoDataText("NO DATA"); } else { mChart.setNoDataText("Loading Data from Server... "); } – Parama Sudha Jan 07 '16 at 08:33
0

you can change it as below ,

LineChart mChart;

mChart.setDescription("");

mChart.setNoDataTextDescription("You need to provide data for the chart.");

mChart.setNoDataTextDescription("Your message");
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142