How to use JfreeChart to display dates on the X axis of a line chart

I tried to display the line chart with time (HH: mm: SS) as X axis and number (as y axis)

for (Row row : sheet)
{
    Double sar_Val = poiGetCellValue(sar);
    Double date_val = poiGetCellValue(date);

    if(sar_Val != null && date_val != null)
    {
        series1.add(date_val,sar_Val);
    }
    dataset.addSeries(series1);
}

//Poigetcellvalue in the above code returns a double according to the data type

The problem is that I have to convert the data under the "time" column in the format HH: mm: SS to a double value and fill in Series1, because the add function only accepts the double value Once I convert the value to double, how do I display the time in the X axis, or is there any other method that can be added to the XY series?

Solution

Use org jfree. data. time. Timeseries stores values instead of xyseries and timeseries collection for datasets

This will allow you to add regulartimeperiod and double instead of two double The regulartimeperiod is implemented by day, so the final code is as follows:

private XYDataset createDataset() {
    TimeSeries series1 = new TimeSeries("Data");
    Date date = new Date();
    series1.add(new Day(date),46.6);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series1);
    return dataset;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>