Question

I need to change this code in such a way that X Axis contains time stamps in the format "H:M", e.g. 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;
        }
Was it helpful?

Solution

Use setDateFormatOverride() on the axis with a suitable DateFormat:

axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top