2

I've created a XYChart with numerical values different (for example temperatue with pressure) so I want to draw my own axeS just beside my chart. To do the following I've to unshow the YAxis, how should I do that ?

PhilippeVienne
  • 550
  • 8
  • 19

3 Answers3

8

By using a trick: The Chart needs the Y Axis to remain in place so it knows where to render your content. You can, however, hide it. Hide the tick labels and set the axis' opacity to 0 using this code:

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

The axis will still be there, but not shown.

sarcan
  • 3,145
  • 19
  • 22
2

I found that if I hid the chart using the following code:

chart.getXAxis().setTickLabelsVisible(false);
chart.getXAxis().setTickMarkVisible(false);
((Path)chart.getXAxis().lookup(".axis-minor-tick-mark")).setVisible(false);

Then I get about ~10 pixels less blank space on the bottom. IF the space was an issue for your application then you could use css offsets to correct it. This solution may have more predictable offsets.

Doctor Parameter
  • 1,202
  • 2
  • 15
  • 21
  • This is the best solution posted in this page. Unlike the other answers, your solution keeps the grey line at the bottom bound of the plot area and only removes the ticks. – RestInPeace May 28 '18 at 01:42
1

SOLVED: I got this to work for sharing a common x-axis for two charts stacked vertically:

enter image description here

  1. Create two charts, each with their own identical copy of the x-axis object, setting identical upper and lower bounds (optionally by binding).

  2. Then hide the x-axis in the second chart like this:

chart = new LineChart<Number,Number>(xaxis2,yaxis2) {
{// hide xAxis in constructor, since not public
            getChartChildren().remove(getXAxis());
            // not getPlotChildren()
      }
};
  1. You'll want to set the widths of your y-axes to be the identical, e.g.

    int w = 60;
    yaxis.setMaxWidth(w);
    yaxis.setMinWidth(w);
    yaxis.setPrefWidth(w);
    yaxis2.setMaxWidth(w);
    yaxis2.setMinWidth(w);
    yaxis2.setPrefWidth(w);
    
George Forman
  • 600
  • 5
  • 7