I have created a simple line chart where I compare the current years values to past years (could be an average or not).
The issue is that as this is for UK Academic purposes I want the months to run from June through to June the following year.
Currently my code looks like:
xAxis.setLabel("Date/Month");
xAxis.setTickLabelRotation(90);
xAxis.setAutoRanging(false);
xAxis.setLowerBound(1);
xAxis.setUpperBound(12);
xAxis.setTickUnit(1.0);
xAxis.setTickLabelFormatter(new StringConverter<Number>() {
@Override
public String toString(Number month) {
logger.debug("Converting " + month);
return new DateFormatSymbols().getMonths()[month.intValue()-1];
}
@Override
public Number fromString(String string) {
try {
Date date = new SimpleDateFormat("MMMM").parse(string);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.MONTH);
} catch (ParseException ex) {
logger.error("Parse Exception");
}
return 0;
}
});
yAxis.setLabel("Units");
where the series are created using a simple function:
private XYChart.Series createSeries(String name, List<AccountUtilities> data) {
XYChart.Series series = new XYChart.Series();
series.setName(name);
for (AccountUtilities utility : data) {
String[] dateParts = utility.getStartdate().split("-");
Double dateCode = Double.valueOf(dateParts[1]);
series.getData().add(new XYChart.Data( dateCode , utility.getGasunits()));
}
return series;
}
My current thought is that I can reindex the months as June = 1, July = 2 etc. to get the values into the chart in the correct order and then decode them into their 'correct' values June = 6 when I get setTickLabelFormatter to do its thing but this seems a long way around.
Is there a nifty feature of javafx charting that I'm missing?
Current resources used: