Reputation: 543
I have graph which show speed value on Y axis. I want to show exactly 2 values: avg value (i. e. middle value label) and max value. I'm using YAxis.setLabelCount(2)
to set only two labels on Axis. But graph always showing me min value and another one or two values. The behavior that i want:
If we have max speed 2.4 miles (or km) - show label with max speed. Also show half from this speed label (1.2)
Upvotes: 1
Views: 971
Reputation: 537
YAxis.setLabelCount(2, true) there is another paramerter called force, by set it as true, the axis will have the exactly number as label count you set.
Updated July 19th: To display label on special value, the ValueFormatter can be invoked, and the entries labels can be changed manually. It's better to change the entries of labels after it is updated by MPChart, but I cannot found the actual callback or something else which is "after the entries is updated", so I changed it in ValueFormatter, also works:
object: ValueFormatter() {
override fun getAxisLabel(value: Float, axis: AxisBase): String {
axis.mEntries[0] = mAverage
axis.mEntries[1] = mMax
return getFormattedValue(value)
}
override fun getFormattedValue(value: Float) = String.format("%.1f", value)
}
Do make sure mAverage and mMax is in the range of y-axis labels!
Upvotes: 2