I would like to extend behaviour of an 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 objects which can be only casted to OHLCItem, but can not be casted to my custom class. Here's how I define my custom 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;
}
}
So, is there any way I can retrieve objects of my custom class from the OHLCSeries?
If you look through the source code for the OHLCSeries
class, you'll see the issue pretty quickly (in the add(OHCLItem)
method). You will need to create your own CustomOHLCSeries
class.