我需要更改此代码,以使X轴包含格式为“ H:M”的时间戳,例如10:00。
private static XYDataset createCategoryDataset(Map<Integer,List<Task>> staffLevels) { String series1 = "Task demand"; DefaultXYDataset dataset = new DefaultXYDataset(); double[][] data = new double[2][staffLevels.size()]; int min_per_hour = 60; for (int i=0; i<staffLevels.size(); i++) { int seconds = i*Parameters.MIN_TIME_UNIT*60; int hours = (i*Parameters.MIN_TIME_UNIT) / min_per_hour; int minutes = (seconds / min_per_hour) % min_per_hour; data[0][i] = hours + ":" + minutes; data[1][i] = staffLevels.get(i).size(); } dataset.addSeries(series1, data); return dataset; }
使用setDateFormatOverride()与合适的轴DateFormat:
setDateFormatOverride()
DateFormat
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));