Skip to content
Advertisement

How to get X pixel value from date index or string in JFreeChart?

I have the following sample app :

JavaScript

How to implement the 2 “getX()” methods above, so they will return the X pixel values by inputting date index or date string ?

Advertisement

Answer

Given a ChartPanel, seen here, the following method finds the index item in the priceSeries and converts its time to Java2D coordinates relative to the chart.

JavaScript

The TimeSeries method getIndex() can be used to find the the index of a TimeSeriesDataItem having the RegularTimePeriod corresponding to a given date string; the resulting index can be passed to getX(int index).

JavaScript

Add a line like this to the chartMouseMoved handler to see the correspondence between coordinates:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement