Skip to content

LineChart: Axis mLabelRotatedHeight is counted twice when calculating offsets #2369

@matiash

Description

@matiash

It looks like the legend adds this height to its own offset. This happens in every case, but it's most noticeable when the labels are long, since the space taken is bigger. You can clearly see it (blank space between chart and legend) when comparing these two screenshots

and

(This was tested with the latest commit, as of today)

Steps to reproduce

Edit LineChartActivity1.java in the sample project, and add the following lines to the onCreate() method:

xAxis.setLabelRotationAngle(-90f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        return "A long text for value" + (int)value;
    }

    @Override
    public int getDecimalDigits() {
        return -1;
    }
});

I believe the bug is in BarLineChartBase.calculateLegendOffsets() which adds getXAxis().mLabelRotatedHeight to the top offset of the legend (or bottom, depending on its position):

if (getXAxis().isEnabled() && getXAxis().isDrawLabelsEnabled())
    offsets.bottom += getXAxis().mLabelRotatedHeight;

I tried commenting out those lines and the problem goes away, but I'm not sure if there could be any other repercussions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconfirmed bugs or otherwise incorrect behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions