Hi,
I am extending the DefaultHighLowDataset class in my application and I need to access the date object for a particular index value. Specifically, I would expect a getDateValue() method similar to getHighValue().
In release 0.93 the date[] array was protected and I could at least access it in my subclass. However, date[] is now private in 0.94 and there is no accessor method.
I know I can modify the code but I was wondering if there is a particular design reason for completely hiding date objects. Am I overlooking something?
Thanks,
--Johann
Access to dates[] in DefaultHighLowDataset
Re: Access to dates[] in DefaultHighLowDataset
Johann Lynch wrote:
> I know I can modify the code but I was wondering if there is
> a particular design reason for completely hiding date
> objects. Am I overlooking something?
No particular reason. The DefaultHighLowDataset class is a pretty minimal implementation of the HighLowDataset interface. One thing to note is that JFreeChart doesn't actually see Date objects through any of the datasets, it sees only Number objects (that may be interpreted as the number of milliseconds since 1-Jan-1970 in some cases).
I've just added the following method to the DefaultHighLowDataset class to give access to the underlying date:
/**
* Returns the x-value for one item in a series, as a Date.
* <p>
* This method is provided for convenience only.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the x-value as a Date.
*/
public Date getXDate(int series, int item) {
return date[item];
}
Hope that helps.
Regards,
DG
> I know I can modify the code but I was wondering if there is
> a particular design reason for completely hiding date
> objects. Am I overlooking something?
No particular reason. The DefaultHighLowDataset class is a pretty minimal implementation of the HighLowDataset interface. One thing to note is that JFreeChart doesn't actually see Date objects through any of the datasets, it sees only Number objects (that may be interpreted as the number of milliseconds since 1-Jan-1970 in some cases).
I've just added the following method to the DefaultHighLowDataset class to give access to the underlying date:
/**
* Returns the x-value for one item in a series, as a Date.
* <p>
* This method is provided for convenience only.
*
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return the x-value as a Date.
*/
public Date getXDate(int series, int item) {
return date[item];
}
Hope that helps.
Regards,
DG
Re: Access to dates[] in DefaultHighLowDataset
Thanks Dave. That will save me having to recreate the Date objects in my application.
--Johann
--Johann