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.

0


source to share


2 answers


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)

+1


source


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);

      

0


source







All Articles