Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - Multiple lines for chart.setNoDataText

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.

like image 326
morhenny Avatar asked Jul 20 '18 11:07

morhenny


1 Answers

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.

like image 83
Misha Akopov Avatar answered Oct 23 '22 03:10

Misha Akopov