MPAndroidChart - Multiple lines for chart.setNoDataText

morhenny :

I'm using the MPAndroidChart library which has a string written on the chart if no data is available yet.

If the string is too long, it seems to just overflow to both sides of the screen so I'm wondering if it's possible to make that text use multiple lines, because neither \n, <p>, nor <br> work.

The method to set that text is chart.setNoDataText(String) where chart is a LineChart view.

Misha Akopov :

It is impossible, if you take a look at source of the library, here how it draws text

    @Override
    protected void onDraw(Canvas canvas) {
        if (mData == null) {    
            boolean hasText = !TextUtils.isEmpty(mNoDataText);    
            if (hasText) {
                MPPointF c = getCenter();
                canvas.drawText(mNoDataText, c.x, c.y, mInfoPaint);
            }    
            return;
        }

        if (!mOffsetsCalculated) {

            calculateOffsets();
            mOffsetsCalculated = true;
        }
    }

Here main line is

canvas.drawText(mNoDataText, c.x, c.y, mInfoPaint);

Library draws text mNoDataText as single line, starting from c.x, c.y.
canvas.drawText() doesn't know how to handle newlines.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=78017&siteId=1