4

I want to display some dates in the X axis of a histogram chart, but i don't understand how i can do it

with this code i can create a simple histogram with couples of x-y values, but they can olny be numbers, not date:

DefaultTableXYDataset dataset = new DefaultTableXYDataset();
    XYSeries serie = new XYSeries("Andamento consumi", true, false);

    serie.add(30, 8.3);
    serie.add(31, 7.1);
    serie.add(1, 8.7);
    serie.add(2, 6.0);
    serie.add(3, 11.9);

    dataset.addSeries(serie);

    JFreeChart chart = ChartFactory.createHistogram("Grafico di prova", "Giorni", "Consumi", dataset, PlotOrientation.VERTICAL,true,true,true);

    ChartFrame frame = new ChartFrame("Titolo finestra", chart);
    frame.pack();
    frame.setVisible(true);

Is there a way to insert dates instead of numbers?

Maik
  • 811
  • 3
  • 22
  • 35

1 Answers1

2

If you are dealing with dates use a TimeSeriesCollection or TimePeriodValuesCollection dataset instead of DefaultTableXYDataset.

jzd
  • 23,473
  • 9
  • 54
  • 76
  • I am trying to understand how this TimeSeriesCollection works. I see i have to add a TimeSeries, which has tio be constructed using a RegularTimePeriod.. I am a bit confused... Can you please provide some example code? Thanks – Maik Feb 25 '11 at 15:23
  • @Maik, "How to constructor or use TimeSeriesCollections" is a different question. Please create a new post for it. Thanks – jzd Feb 25 '11 at 15:25
  • ok i have created it here: http://stackoverflow.com/questions/5119244/how-to-construct-and-use-timeseriescollections – Maik Feb 25 '11 at 15:43