0

I am using Jfreechart. I have the code like this:

TimeSeries t1 = new TimeSeries("EUR/GBP");
t1.add(new Day(4, MonthConstants.JANUARY, 2001), new Double(1.5807));

But I get String from my SQL query. TimeSeries accepts only RegularTimePeriod or TimeSeriesDataItem.

Please let me know how to convert a String into RegularTimePeriod.

Thanks in Advance.

4

1 回答 1

3

首先,您可以通过使用 SimpleDateFormat 解析 mysql 日期字符串来获取 Date 对象,然后使用带有 Date arg 的构造函数创建您的 RegularTimePeriod。

基本上(假设 mysqlDateStr 是您来自 mysql 查询的字符串):

SimpleDateFormat standardDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// (Define your formatter only once, then reuse)

Date myDate = standardDateFormat.parse(mysqlDateStr);
// (you may want to catch a ParseException)

t1.add(new Day(myDate), new Double(1.5807));
于 2009-01-07T16:45:11.033 回答