如何扩展 OHLCItem class 并在 OHLCSeries 中使用它
How can I extend an OHLCItem class and use it in OHLCSeries
我想扩展 OHLCItem class from the JFreeChart library and I would like to use those custom objects to build an OHLCSeries with them. This works ok. However, when I am trying to retrieve those objects from the OHLCSeries using the getDataItem(int index)
method, I only receive ComparableObjectItem 对象的行为,这些对象只能转换为 OHLCItem,但不能转换为我的自定义 class。这是我定义自定义 class:
的方式
public class CustomOHLCItem extends OHLCItem {
private boolean isJoinedCandle;
private OHLCItem clickedItem;
private OHLCItem neighbourItem;
public CustomOHLCItem(RegularTimePeriod period, double open, double high, double low, double close, boolean isJoinedCandle) {
super(period, open, high, low, close);
this.isJoinedCandle = isJoinedCandle;
}
public boolean isJoinedCandle() {
return isJoinedCandle;
}
public OHLCItem getClickedItem() {
return clickedItem;
}
public void setClickedItem(OHLCItem clickedItem) {
this.clickedItem = clickedItem;
}
public OHLCItem getNeighbourItem() {
return neighbourItem;
}
public void setNeighbourItem(OHLCItem neighbourItem) {
this.neighbourItem = neighbourItem;
}
}
那么,有什么方法可以从 OHLCSeries 中检索我自定义 class 的对象吗?
如果您查看 OHLCSeries
class 的源代码,您会很快发现问题(在 add(OHCLItem)
方法中)。您将需要创建自己的 CustomOHLCSeries
class.
我想扩展 OHLCItem class from the JFreeChart library and I would like to use those custom objects to build an OHLCSeries with them. This works ok. However, when I am trying to retrieve those objects from the OHLCSeries using the getDataItem(int index)
method, I only receive ComparableObjectItem 对象的行为,这些对象只能转换为 OHLCItem,但不能转换为我的自定义 class。这是我定义自定义 class:
public class CustomOHLCItem extends OHLCItem {
private boolean isJoinedCandle;
private OHLCItem clickedItem;
private OHLCItem neighbourItem;
public CustomOHLCItem(RegularTimePeriod period, double open, double high, double low, double close, boolean isJoinedCandle) {
super(period, open, high, low, close);
this.isJoinedCandle = isJoinedCandle;
}
public boolean isJoinedCandle() {
return isJoinedCandle;
}
public OHLCItem getClickedItem() {
return clickedItem;
}
public void setClickedItem(OHLCItem clickedItem) {
this.clickedItem = clickedItem;
}
public OHLCItem getNeighbourItem() {
return neighbourItem;
}
public void setNeighbourItem(OHLCItem neighbourItem) {
this.neighbourItem = neighbourItem;
}
}
那么,有什么方法可以从 OHLCSeries 中检索我自定义 class 的对象吗?
如果您查看 OHLCSeries
class 的源代码,您会很快发现问题(在 add(OHCLItem)
方法中)。您将需要创建自己的 CustomOHLCSeries
class.