Reading values from Over lays

Discussion about JFreeChart related to stockmarket charts.
Locked
amarnath578
Posts: 22
Joined: Tue Aug 25, 2009 8:02 pm
antibot: No, of course not.

Reading values from Over lays

Post by amarnath578 » Thu Sep 10, 2009 3:50 pm

Hi,

I have a Chart, which displays the data Price vs Time of a selected stock, with several overlays added to it. Let us assume that the chart displays price movement in a day and it has an overlay such as Exponential Moving Average.

The requirement is to display EMA value as the user mouse hovers on the chart. I am able to do the following things:

1) Capturing the point at which mouse is placed and convert these co-ordinates to dataset co-ordinates i.e (time1, price1), (time2, price2).

// Retrieve the underlying component that generates the mouse event.
final TRInteractiveChartPanel chartPanel = (TRInteractiveChartPanel) event.getSource();

// This point holds the location of the mouse in java 2D space.
Point java2DPoint = event.getPoint();

// Read the underlying Plot at the specified point.
plotInfo = chartPanel.getPlotInfoAt(java2DPoint);

// Convert the 2D co-ordinates to dataset co-ordinates.
Point2D datasetPoint = java2DToValue(event.getPoint());

2) I know the data set representing the overlay on the chart, this is the dataset that has all the EMA values.

TRStatisticalModelDataSet dataSet = (TRStatisticalModelDataSet) plotInfo.getPlot().getDataset(2);

3) I am able to read the (time, price) values successfully

Point2D datasetPoint = java2DToValue(event.getPoint());
long time = datasetPoint.getX();
long price = datasetPoint.getY();

4) Now I would like to read the EMA value at this time from the overlay chart. I know that time, as shown above, at which the EMA needs to be calculated. Please help me reading the EMA value from the dataset.

Thanks.

Locked