问题
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