title: Adding date/time to JFreeChart graph
body: <p>I currently have a method which queries a database for values, and plots them to a graph. The only problem is, the <code>time</code> variable is a long, and results in my graph looking like this:</p>
  
  <p><img src="https://i85.photobucket.com/albums/k52/Dommmminic/graph.jpg" alt="graph"></p>
  
  <p>I want to convert it to a date format and then add it to the graph.</p>
  
  <p>How can I do this?</p>
  
  <p>Here is my graph code:</p>
  
  <pre><code>private Long time;
  private Long intensity;
  public XYSeries series = new XYSeries("Sensor");
  private XYDataset xyDataset;
  public JFreeChart chart;
  
  xyDataset = new XYSeriesCollection(series);
  chart = ChartFactory.createXYLineChart("Sensor Data", "Time", "Intensity", xyDataset, PlotOrientation.VERTICAL, true, true, false);
  </code></pre>
  
  <p>Here is my method for adding to the graph:</p>
  
  <pre><code>public void GetDustLevels() {
      series.clear();
      try {
          currentSensor = Application.getInstance().getMinesite().getSensors().get(sensorID);
      } catch (Exception e1) {
          e1.printStackTrace();
      }
  
      if (currentSensor != null) {
          sensorKDTree = currentSensor.getSensorData();
          Iterator&lt;Map.Entry&lt;GenericPoint&lt;Long&gt;, String&gt;&gt; allPoints = sensorKDTree.iterator(sensorKDTree.getMin(null), sensorKDTree.getMax(null));
  
          while (allPoints.hasNext()) {
              GenericPoint&lt;Long&gt; timeIntensityPair = allPoints.next().getKey();
              time = timeIntensityPair.getCoord(0);
              intensity = timeIntensityPair.getCoord(1);
              System.out.println("CURRENT SENSOR" + currentSensor);
              System.out.println("TIME: " + time + " " + "INTENSITY: " + intensity);
              series.add(time, intensity);
          }
  
      }
  
  
  }
  </code></pre>
  
  <p>Any help would be GREATLY appreciated! Thank you!</p>
  
  <p>EDIT: I have changed my code to this:</p>
  
  <pre><code>public TimeSeries series = new TimeSeries("Sensor", Date.class);
  public JFreeChart chart;
  private Long time;
  private Long intensity;
  
  TimeSeriesCollection xyDataset = new TimeSeriesCollection(series);
  chart = ChartFactory.createTimeSeriesChart("Sensor Data", "Time", "Intensity", xyDataset, true, true, false);
  </code></pre>
  
  <p>And my new GetDustLevels() method:</p>
  
  <pre><code> public void GetDustLevels() {
      series.clear();
      try {
          currentSensor = Application.getInstance().getMinesite().getSensors().get(sensorID);
      } catch (Exception e1) {
          e1.printStackTrace();
      }
  
      if (currentSensor != null) {
          sensorKDTree = currentSensor.getSensorData();
          Iterator&lt;Map.Entry&lt;GenericPoint&lt;Long&gt;, String&gt;&gt; allPoints = sensorKDTree.iterator(sensorKDTree.getMin(null), sensorKDTree.getMax(null));
  
          while (allPoints.hasNext()) {
              GenericPoint&lt;Long&gt; timeIntensityPair = allPoints.next().getKey();
              time = timeIntensityPair.getCoord(0);
              intensity = timeIntensityPair.getCoord(1);
              System.out.println("CURRENT SENSOR" + currentSensor);
              System.out.println("TIME: " + time + " " + "INTENSITY: " + intensity);
              XYPlot plot = (XYPlot) chart.getPlot();
              DateAxis axis = (DateAxis) plot.getDomainAxis();
              axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy"));
              series.add(new Date(time.longValue()), intensity);
          }
  
      }
  
  
  }
  </code></pre>