I am trying to build a series chart using JavaFX, where data is inserted dynamically.
Each time that a new value is inserted I would like to check if this is the highest value so far, and if so, I want to draw an horizontal line to show that this is the maximum value.
In JFree chart I would have used a ValueMarker, but I am trying to do the same with JavaFX.
I tried using the Line object, but it is definitely not the same, because I cannot provide the Chart values, it takes the relative pixel positions in the windows.
Here is the screenshot of chart I want to achieve:
http://postimg.org/image/s5fkupsuz/
Any suggestions? Thank you.
To convert chart values to pixels you can use method
NumberAxis#getDisplayPosition()
which return actual coordinates of the chart nodes.Although these coordinates are relative to chart area, which you can find out by next code:
Note
localToScene()
method which allows you to convert any coordinates to Scene ones. Thus you can use them to update your value marker coordinates. Make sure you makelocalToScene
call after your Scene have been shown.See sample program below which produces next chart: