Giter Site home page Giter Site logo

Comments (5)

PhilJay avatar PhilJay commented on May 5, 2024

Thank you for your input.
Are the labels also cut on a vertical axis? Or is this just your screenshot?

Currently the chart does not support wrapping the legend. But I am working on an update that allows wrapping right now.

What you can do is call

Legend l = mChart.getLegend();
l.setFormToTextSpace(..); // make space smaller
l.setFormSize(...); // make form smaller

...to save some space.
You can also edit the library and change the text size of the legend labels.
A method for this is also coming in the next update.

A little suggestion: If you have limited space and are using a legend anyway, you can call

mChart.setDrawXValues(false);

which will save some space inside the chart ant make it look better.

Regards,
Phil

from mpandroidchart.

dlesniakdev avatar dlesniakdev commented on May 5, 2024

They are cut on bottom a little bit when you are using PieChar from what I noticed.
I handled this already with changing this lane in your library from:

posY = getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f;

to:

posY = getHeight() - mLegend.getOffsetBottom() / 2f - formSize / 2f - 4f;

in your Chart.java at 659lane.

If you could point me out where to extend the Chart Object on screen so I can fit the wrapped Legend here I'd make it myself.
At the moment I am able to wrap it by editing your library but if I have many records I do not have space to place it. So if there is option to extend a space under graph without making graph bigger itself, that would be nice.
Obviously if it would be too much work to you now, I will wait for library update :)

Thanks for suggestion mate, but this is temp graph just to show the legend issue. I learned the basics from your readme.
Also thanks for saving space tip, but I have to make graph with 15 objects inside so in this particular case it won't help me much, sadly.

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

Thank you for pointing out the issue concerning the vertical clipping. I must have not noticed this during testing and will fix it in the next update.

The PieChart legend in general has some issues I need to fix, so you will probably have to wait for the next update.

Also check out the example project because the readme by far does not list up and explain all features and is outdated in some cases (due to the huge amount of changes I made during the past weeks).

Regards,
Phil

from mpandroidchart.

PhilJay avatar PhilJay commented on May 5, 2024

I just fixed the issue concerning the vertical clipping. It will be published in the next update.

If you want to fix it right away, you need to replace the calculateOffsets() method of the PieChart with this method:

    @Override
    protected void calculateOffsets() {

        if (mLegend == null)
            return;

        // setup offsets for legend
        if (mLegend.getPosition() == LegendPosition.RIGHT_OF_CHART) {

            mLegend.setOffsetRight(mLegend.getMaximumEntryLength(mLegendLabelPaint));
            mLegendLabelPaint.setTextAlign(Align.LEFT);

        } else if (mLegend.getPosition() == LegendPosition.BELOW_CHART_LEFT
                || mLegend.getPosition() == LegendPosition.BELOW_CHART_RIGHT) {

            mLegend.setOffsetBottom(mLegendLabelPaint.getTextSize() * 3.5f);
        }

        if (mDrawLegend) {

            mOffsetBottom = Math.max(mOffsetBottom, mLegend.getOffsetBottom());
        }

        mLegend.setOffsetTop(mOffsetTop);
        mLegend.setOffsetLeft(mOffsetLeft);

        prepareContentRect();

        float scaleX = (float) ((getWidth() - mOffsetLeft - mOffsetRight) / mDeltaX);
        float scaleY = (float) ((getHeight() - mOffsetBottom - mOffsetTop) / mDeltaY);

        Matrix val = new Matrix();
        val.postTranslate(0, -mYChartMin);
        val.postScale(scaleX, -scaleY);

        mMatrixValueToPx.set(val);

        Matrix offset = new Matrix();
        offset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom);

        mMatrixOffset.set(offset);
    }

... and undo all changes you made to the legend drawing.

Regards,
Phil

from mpandroidchart.

dlesniakdev avatar dlesniakdev commented on May 5, 2024

Thanks for your time and answers, I replaced the method already thanks for that listing too.

Have fun with coding and good luck with your library

from mpandroidchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.