Adding Axis Titles to mpandroidchart

我怕爱的太早我们不能终老 提交于 2019-12-05 08:38:15
Sriram Thiagarajan

I have found the solution and I will post it for future reference for other people. I found the vertical textview from the following link.

Vertical (rotated) label in Android

        xAxisName = new TextView(getActivity());
        xAxisName.setText("Date");
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        params.setMargins(0, 0, 0, 20);

        VerticalTextView yAxisName = new VerticalTextView(getActivity(),null);
        yAxisName.setText("Yaxis Label");
        FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

        container.addView(xAxisName, params);
        container.addView(yAxisName,params2);

I suggest that you ( use additionalTextViews outside the chart) or modify the library to your purpose.

It's currently not supported by default.

There is a easy way that set the top axis space by setSpaceTop, set the margin between the TextView

You can use IndexAxisValueFormatter like code below

final ArrayList<String> axiss = new ArrayList<>();
    axiss.add("one");
    axiss.add("two");
    axiss.add("three");
    axiss.add("four");
    axiss.add("five");

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
    xAxis.setDrawLabels(true);
    xAxis.setGranularity(1f);
    xAxis.setLabelRotationAngle(+90);

    xAxis.setValueFormatter(new IndexAxisValueFormatter(axiss));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!