Jfreechart bar graph with dates

I want to display some dates on the x-axis of the histogram chart, but I do not understand how I can do this

with this code, I can create a simple histogram with pairs of xy values, but they can be numbers, not dates:

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?

+3
source share
1 answer

If you are dealing with dates, use TimeSeriesCollectionor TimePeriodValuesCollectiona dataset instead DefaultTableXYDataset.

+1
source

Source: https://habr.com/ru/post/1794737/


All Articles