XChart
XChart copied to clipboard
Format Y axis labels
It is possible to change the decimal pattern format of the y-axis, however it would be great if it also was possible to override the whole label formatting. This could also help solving the use of time / date in the y-axis
You can use custom axis tick calculator. See #217
Yeah, we have setYAxisDecimalPattern()
but no setYAxisDatePattern()
like we have for the X-Axis. Why would you want dates in the y-axis though?
You can always use something like this:
Map<Object, Object> customYAxisTickLabelsMap = new HashMap<>();
customYAxisTickLabelsMap.put(1.0, "max c");
customYAxisTickLabelsMap.put(6.0, "max b");
customYAxisTickLabelsMap.put(9.0, "max a");
chart.setCustomYAxisTickLabelsMap(customYAxisTickLabelsMap);
or
double[] xData = xySeries.getXData();
Map<Object, Object> customTickLabelsMap = new HashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
for (double d : xData) {
Date date = new Date((long) d);
String label = sdf.format(date);
customTickLabelsMap.put(d, label);
}
chart.setCustomXAxisTickLabelsMap(customTickLabelsMap);
but for the y-axis of course.
the new packet version 3.6.1 has no method setYAxisDecimalPattern() , which version we can use it
Yeah, we have
setYAxisDecimalPattern()
but nosetYAxisDatePattern()
like we have for the X-Axis. Why would you want dates in the y-axis though?You can always use something like this:
Map<Object, Object> customYAxisTickLabelsMap = new HashMap<>(); customYAxisTickLabelsMap.put(1.0, "max c"); customYAxisTickLabelsMap.put(6.0, "max b"); customYAxisTickLabelsMap.put(9.0, "max a"); chart.setCustomYAxisTickLabelsMap(customYAxisTickLabelsMap);
or
double[] xData = xySeries.getXData(); Map<Object, Object> customTickLabelsMap = new HashMap<>(); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd"); for (double d : xData) { Date date = new Date((long) d); String label = sdf.format(date); customTickLabelsMap.put(d, label); } chart.setCustomXAxisTickLabelsMap(customTickLabelsMap);
but for the y-axis of course.
the new packet version 3.6.1 has no method setYAxisDecimalPattern() , which version we can use it