0

I have a LineChart in JavaFX like below,

enter image description here

If i access the above chart , i get the whole chart area along with axis. (e.g) if i add it in a Group, plot area + axis is added which is obvious.

Is it possible to get only the plot area without the axis?

user3164187
  • 1,382
  • 3
  • 19
  • 50
  • Are you trying to hide the axes or do you want to access the plot area to to modify it while the axes are still visible? – Markus Köbele Feb 15 '18 at 12:49
  • @MarkusK I want to access the plot area to modify it without hiding the axes . – user3164187 Feb 15 '18 at 12:51
  • Modify it how? What are you actually trying to do? If you just want to change its appearance, you should use CSS. If you want to add nodes to it, you should [subclass `LineChart` and override `layoutPlotChildren()`](https://stackoverflow.com/questions/38871202/how-to-add-shapes-on-javafx-linechart). "If I add it to a `Group`": you simply can't do this; the plot area is already part of the scene graph, and you can't have the same node multiple times in the scene graph. – James_D Feb 15 '18 at 17:03
  • @James_D I just wanna know whether its possible to access plot area similar to accessing the axes [link](https://stackoverflow.com/a/16913062/3164187) mentioned in this answer. An example scenario is, if i want to handle a mouse click on the chart's plot area and if i add `chart.setOnMouseClicked` this event will be invoked even if i click on axis. – user3164187 Feb 16 '18 at 12:20
  • 1
    Lookups are pretty ugly: you can do `Node plotContent = chart.lookup(".plot-content");`. You need to make sure the chart has actually been rendered (or at least that CSS has been applied), the lookup will return null otherwise. There's probably a better way... just can't see it right now. My instinct is to try to avoid needing to do this, though... – James_D Feb 16 '18 at 12:24

1 Answers1

0

I believe an option you could try is to hide the axes. Referring to this question. Hide the the axes as follows:

chart.getYAxis().setTickLabelsVisible(false);
chart.getYAxis().setOpacity(0);

chart.getXAxis().setTickLabelsVisible(false);
chart.getXAxis().setOpacity(0);
TM00
  • 1,330
  • 1
  • 14
  • 26