如何将字符串转换为TimeSeriesDataItem

时间:2021-07-21 21:44:30

I am using Jfreechart. I have the following code:

我正在使用Jfreechart。我有以下代码:

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.

但是我的SQL查询以String格式给出了日期,并在Double中给出了值。我想使用TimeSeriesDataItem。请告诉我如何将我的String转换为TimeSeriesDataItem。请告诉我如何将Double值添加到TimeSeriesDataItem。

Thanks in Advance.

提前致谢。

2 个解决方案

#1


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

1)将您的日期从String转换为java.util.Date

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

2)使用扩展RegularTimePeriod的类之一包装此Date实例。例如。 RegularTimePeriod p =新日(myDate)

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

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.

日期字符串的格式是什么?假设格式为DD-MM-YY。

First convert the string to a Date 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 takes RegularTimePeriod and Double as arguments So create a RegularTimePeriod object and add it to the series.

TimeSeries add将RegularTimePeriod和Double作为参数,因此创建一个RegularTimePeriod对象并将其添加到系列中。

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

#1


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

1)将您的日期从String转换为java.util.Date

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

2)使用扩展RegularTimePeriod的类之一包装此Date实例。例如。 RegularTimePeriod p =新日(myDate)

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

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.

日期字符串的格式是什么?假设格式为DD-MM-YY。

First convert the string to a Date 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 takes RegularTimePeriod and Double as arguments So create a RegularTimePeriod object and add it to the series.

TimeSeries add将RegularTimePeriod和Double作为参数,因此创建一个RegularTimePeriod对象并将其添加到系列中。

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