How to add String labels to both x and y axis in MPAndroidChart

回眸只為那壹抹淺笑 提交于 2019-12-11 04:18:37

问题


I am trying to add a String Label in order to label both the domain (x-axis) and the range (y-axis) of my LineChart, as shown in the picture below.

Any suggestions on how to do it using MPAndroidChart?


回答1:


(Turning @Ironman's comment into an answer:)

As of MPAndroidChart 3.0.1 this is currently not possible using the API exposed by the library. You will need to add additional TextView outside the chart, or modify the library to your purpose.

If you want to modify the library to your own purpose, you will need to study the source code XAxisRenderer and subclass it to add functionality to draw the axis label you want.




回答2:


You can apply this code

mChart.getAxisLeft().setEnabled(true); //show y-axis at left
mChart.getAxisRight().setEnabled(false); //hide y-axis at right


mChart.getAxisLeft().setValueFormatter(new IAxisValueFormatter() {
    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        return "string_" + (int) value; // yVal is a string array
    }
});


来源:https://stackoverflow.com/questions/40656214/how-to-add-string-labels-to-both-x-and-y-axis-in-mpandroidchart

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