Looking at various JavaFX examples for a bar graph, I don't see any examples of how to add descriptive (label) text to each bar in the graph.
All the examples I've seen are well-behaved 2-D with static values for x-y.
But what if you have data like this:
You could graph any two of these, but the third value? I'm guessing to display that, you'd need to "decorate" each bar with a label showing that value. I've experimented with creating a label and going through the series collection but nothing has worked.
For example, you might have a graph showing year and Amount where each bar is the "error count", but you need to then add the "user" (name) to the bar.
Not sure how to label each bar with the third value in FX or if it's even possible. No examples I could find.
(Is this actually just a 3D chart? Hope that's not my only option.)
So instead of setting the category axis to just 2017, you could set it to 2017 + " " + userName, for example:
That will set the category name to year + user. However what you probably want is to have multiple series of data with the username written directly next to the bar. In which case the following wouldn't work:
As the categories wouldn't match as you would wish.
So what you might want to do is to have just
Then use a similar trick to that from the StackOverflow answer to add an additional text item into the chart to label each individual bar:
The above code is adding in an extra label which states the value of the bar, but you can replace the text in the example with a username as per your requirements.
posted 3 years ago
Thanks for your reply.
Since there is no built-in way to just add a simple label to a bar, I "solved" it by adding the label information as part of the axis label.
Not what I really wanted, but don't have days to work on something so basic. Can't believe I'm the only one who might want to add an explanatory label next to a bar, but whatever...