5

I have built a Line Chart using SceneBuilder. I seem to have little control over the axes values. The x-axis is the one giving me the most trouble.

I am adding the series data in lines like this, within a loop:

openSeries.getData().add(new XYChart.Data(masher.getIncrement(), masher.getOpen()));

Where masher.getIncrement() is a String of an int value; masher.getOpen() is just a double.

The increment values are in order such as: "12", "13", "15", "17".

The data graphs okay, but the x=axis categories all pile on top of themselves...

My Line Chart

How do I get them to spread out? Ideally, one per vertical grid line?

Eddie T
  • 101
  • 5

1 Answers1

5

I may have stumbled on to the answer. In SceneBuilder, under the Line Chart's CategoryAxis, in its Properties is an Animated check box. Unchecking it - but leaving Auto Ranging just below it checked - looks to have solve the x-axis problem.

enter image description here

Eddie T
  • 101
  • 5
  • I believe the behavior is a bug with `CategoryAxis`, or at least it's not as user-friendly as it could be. One workaround, as you've discovered, is to disable animation. Another, if I recall correctly, is to make sure you add all the appropriate categories to the [`CategoryAxis#getCategories()`](https://openjfx.io/javadoc/13/javafx.controls/javafx/scene/chart/CategoryAxis.html#getCategories()) list (and then you should be able to enable animation). That being said, it seems like your categories are numbers; are you sure your x-axis shouldn't be a `NumberAxis`? – Slaw Nov 26 '19 at 21:34