I have problems with adding a line at a defined position in JavaFX. The line has to be line a constant line as shown here: How to add a value marker to JavaFX chart?
My problem is, that my layout definition is a bit more complicated. Have a look:
The important part is the one on the top. I want to have the line on the y=60 line. The left part with the RadioBoxes is a VBox. The part with the (Scatter-)Chart is a StackPane (because I want it to fill the rest of the width). Inside this StackPane is the chart and a Group. The only child of the Group is the line.
I think the problem is, that the StackPane centers the Group with the line above the chart. But I can't get the combination of layouts which 1. stretches the chart 2. sets the Line above the chart 3. doesn't center the line
I tried lots of combinations but I just can't get it the way I want. Does anybody have an idea?!
Unfortunately, ValueMarkers are not supported in XYCharts (that's probably the place in the hierarchy were it should be done) (Mis-)using data with constant value is a hack which might (or not) be acceptable/possible in some contexts.
A cleaner way out is a custom Chart that supports such markers. F.i. a custom ScatterChart like:
A snippet testing the chart (f.i. insert into the online example in oracle's tutorial):
Addendum:
While I wouldn't recommend the approach in the related question (adding the marker line to the chart's parent and managing its position/length externally) it is possible to use it in resizable containers. The crucial thingies to make it work:
in code (updateShift is the part in the original that calculates the yShift/lineX):
Why don't you add that line into your chart? I have charts where I display the 100, 99, 95 and 50 percentiles, and the way I solve this is to add a line at the correct y-value for each percentile.
To do this, just add a line with two points, one at y=60 x=70 (the left-most x-axis value) and the other one at y=60 and x=120 (the right-most x-axis value).
The upside of this is that you do not have to align the horizontal line yourself manually, the downside being that this horizontal line will also be part of the legend. However, seeing as you do not have a legend that should be OK.
If you decide to add a legend, be sure to name the horizontal line appropriately, l