views:

562

answers:

1

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, mahesh.

+1  A: 

First you can get a Date object by parsing your mysql date string using a SimpleDateFormat, then create your RegularTimePeriod using the constructor with a Date arg.

Basically (assuming mysqlDateStr is your string from mysql query) :

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));
WiseTechi
Of course you would have to change the String in simple date format to match the date.
Ubersoldat