How to convert a string into TimeSeriesDataItem

﹥>﹥吖頭↗ 提交于 2020-01-16 18:51:27

问题


I am using Jfreechart. I have the following code:

TimeSeries t1 = new TimeSeries("EUR/GBP");
t1.add(new TimeSeriesDataItem....);

But my SQL query gives date in String format & value in Double. I want to use TimeSeriesDataItem. Please let me know how to convert my String into TimeSeriesDataItem. Please let me know how to add my Double value to TimeSeriesDataItem.

Thanks in Advance.


回答1:


1) convert your date from String to java.util.Date

2) wrap this Date instance using one of the classes extending RegularTimePeriod. eg. RegularTimePeriod p = new Day (myDate)

3) TimeSeriesDataItem t = new TimeSeriesDataItem (p, a_numeric_value)




回答2:


What is the format of the date string? Assuming the format is DD-MM-YY.

First convert the string to a Date object.

String date_S = "04-06-16"; //your date from SQL
Date date;
SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MM-yy");
try {
   date = sdf2.parse(dateS);
} catch (ParseException e) {
    e.printStackTrace();
}

TimeSeries add takes RegularTimePeriod and Double as arguments So create a RegularTimePeriod object and add it to the series.

RegularTimePeriod rtp = new Date(date);
TimeSeries t1 = new TimeSeries("EUR/GBP");
TimeSeriesDataItem tsdi = new TimeSeriesDataItem(rtp , Double);
t1.add(tsdi);


来源:https://stackoverflow.com/questions/424264/how-to-convert-a-string-into-timeseriesdataitem

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