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

最佳答案

如果浏览OHLCSeries类的源代码,您会很快发现问题(在add(OHCLItem)方法中)。您将需要创建自己的CustomOHLCSeries类。

07-21 18:58