How to convert string to TimeSeriesDataItem
I am using Jfreechart. I have the following code:
TimeSeries t1 = new TimeSeries("EUR/GBP");
t1.add(new TimeSeriesDataItem....);
But my SQL query gives the date in the format String
and the value in Double
. I want to use TimeSeriesDataItem
. Please let me know how to convert my string to TimeSeriesDataItem
. Please let me know how to add a value Double
to TimeSeriesDataItem
.
Thanks in Advance.
source to share
What is the format of the date string? Assuming the format is DD-MM-YY.
First, we convert the string to an object Date
.
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 accept RegularTimePeriod
and Double
the arguments why create an object RegularTimePeriod
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);
source to share