JFreeChart:X轴包含时间戳

时间:2014-03-07 17:28:00

标签: java jfreechart

我需要更改此代码,使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;
        }

1 个答案:

答案 0 :(得分:3)

在轴上使用setDateFormatOverride() DateFormat

axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));