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

2019-07-28 20:51发布

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. a picture of a LineChart with "range" and "domain" labels outside the xAxis

Any suggestions on how to do it using MPAndroidChart?

2条回答
别忘想泡老子
2楼-- · 2019-07-28 21:25

(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.

查看更多
We Are One
3楼-- · 2019-07-28 21:40

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
    }
});
查看更多
登录 后发表回答