MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

AxisLeft SetStartAtZero only works on Screen Rotation

Open rgray00 opened this issue 11 years ago • 3 comments

I am using a line chart on a fragment inside of a viewpager. When I launch the activity it defaults the chart to start the y-axis at 0 even though I have set the chart property to false.

        LineData data = new LineData(xVal, dataSets);
        lineChart.setData(data);
        lineChart.getAxisRight().setEnabled(false);
        lineChart.getLegend().setEnabled(false);
        lineChart.getAxisLeft().setStartAtZero(false); //Set to not start at 0
        lineChart.getAxisLeft().setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
        lineChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
        lineChart.getXAxis().setAvoidFirstLastClipping(true);
        lineChart.getXAxis().setTextSize(8f);
        lineChart.getAxisLeft().setTextSize(8f);
        lineChart.setTouchEnabled(false);
        lineChart.fitScreen();
        lineChart.setLogEnabled(true);

On Activity Start screen shot 2015-03-04 at 4 44 23 pm

On Rotate Landscape screen shot 2015-03-04 at 4 44 37 pm

On Rotate Vertical screen shot 2015-03-04 at 4 44 50 pm

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.github.mikephil.charting.charts.LineChart
        android:id="@+id/lineChart"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

rgray00 avatar Mar 04 '15 21:03 rgray00

Have you tried setting this before calling setData(...)?

chart.getAxisLeft().setStartAtZero(false);
chart.setData(...);

Does it work then? The reason is that upon adding the data to the chart, it calculates the axis. If your specific attributes are not set by then, they wont work until the next refresh.

PhilJay avatar Mar 04 '15 22:03 PhilJay

Nice!, also it seems to be adding padding to the left when I put labels inside the chart like this:

lineChart.getAxisLeft().setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);

rgray00 avatar Mar 04 '15 22:03 rgray00

Yep, sorry for that.

chart.getAxisLeft().setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); currently doesnt work, its a known issue I will fix it in next release.

PhilJay avatar Mar 04 '15 22:03 PhilJay