Maik
Maik

Reputation: 891

jfreechart histogram with dates

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?

Upvotes: 4

Views: 2584

Answers (1)

jzd
jzd

Reputation: 23639

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

Upvotes: 2

Related Questions