jfreechart histogram with dates

半城伤御伤魂 提交于 2019-12-10 17:48:04

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/5118684/jfreechart-histogram-with-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!