Reputation: 43
Does anybody know, if it is possible to hide the axis in a JavaFX ScatterChart
object? Or can anybody think of a simple workaround? I didn't find anything related to this issue in the documentation of the ScatterChart object.
Unfortunately, they are kind of irritating in all kinds of graphs where the axis's values are not, per se, informative (e.g. distance configurations).
Note: the most simple solution to set the visibility attribute of the scales to false unfortunately did not yield the result I was longing for (actually it showed no effect at all).
Upvotes: 3
Views: 3189
Reputation: 6475
When you say "Hide the Axis", I'm assuming you mean hide all the tick marks and tick labels. Please let me know if you mean different.
The first step would be to hide the tick labels - this is pretty straight forward:
xAxis.setTickLabelsVisible(false);
yAxis.setTickLabelsVisible(false);
The second step is hiding the tick marks and all the neat graphics stuff that goes along with the tick marks (like the background colors). The best way I found for doing this is through the CSS. So you'll need to create a CSS file (I created one called test.css
and placed it in my project's base folder) and load it up. Loading it can be done like this:
sc.getStylesheets().add("test.css");
(where sc
is the ScatterChart
object)
This is the CSS code I used to remove all the visuals associated with tick marks:
.axis-tick-mark,
.axis-minor-tick-mark,
.chart-vertical-grid-lines,
.chart-horizontal-grid-lines,
.chart-vertical-zero-line,
.chart-horizontal-zero-line {
-fx-stroke: transparent;
}
.chart-alternative-row-fill, .chart-alternative-column-fill{
-fx-fill: #f5f5f5;
}
Oracle puts out a great CSS reference for JavaFX - but in addition to that, I would recommend downloading the default CSS JavaFX uses. Looking at the default helps tons. You'll find instructions in that link under the "Default Style Sheet" section and also on the web with caspian.css for JavaFX 2.2 and modena.css for Java 8.
Upvotes: 5