MPAndroidChart -Use multiple text instead of “No C

2019-08-11 07:12发布

问题:

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;
            }
        }

回答1:

you can change it as below ,

LineChart mChart;

mChart.setDescription("");

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

mChart.setNoDataTextDescription("Your message");


回答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");