MPAndroidChart -Use multiple text instead of “No C

2019-08-11 06:54发布

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

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-11 07:21

you can change it as below ,

LineChart mChart;

mChart.setDescription("");

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

mChart.setNoDataTextDescription("Your message");
查看更多
▲ chillily
3楼-- · 2019-08-11 07:46

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");
查看更多
登录 后发表回答