如何扩展OHLCItem类并在OHLCSeries中使用它

时间:2016-02-11 13:40:20

标签: java inheritance jfreechart

我想扩展JFreeChart库中OHLCItem类的行为,我想使用这些自定义对象与它们一起构建OHLCSeries。这没问题。但是,当我尝试使用getDataItem(int index)方法从OHLCSeries中检索这些对象时,我只接收ComparableObjectItem个对象,这些对象只能转换为OHLCItem,但不能转换为我的自定义类。以下是我定义自定义类的方法:

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中检索我的自定义类的对象吗?

1 个答案:

答案 0 :(得分:1)

如果您查看OHLCSeries课程的源代码,您会很快看到问题(在add(OHCLItem)方法中)。您需要创建自己的CustomOHLCSeries课程。