2

I use JFreeChart to create a candlestick chart. The horizontal axis is a DateAxis to indicate the time, the vertical axis is a NumberAxis, to indicate the price. As the screenshot shows, is the price axis shown on the left hand side of the chart. Candlestick chart, price values on left hand side

I would like the vertical axis to be displayed on the right hand side of the chart, instead of the left hand side. I have been looking in the class overview for NumberAxis, ValueAxis and Axis classes in JFreeChart but could not find a method which can make this modification. Can somebody please show me how to make this change?

Joe
  • 115
  • 7

1 Answers1

2

As shown here, you can use the XYPlot method setRangeAxisLocation() to set the location of the primary range axis. The image below illustrates the effect of the following addition to this example:

chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);

image

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you for your clear answer trashgod. This solves the issue. It also shows that I was thinking in the wrong direction. I assumed that the Axis determines where it will be located. This is not correct: the Plot determines where the Axis will be positioned. – Joe Nov 25 '19 at 01:51
  • @Joe: Good insight. Visually, the plot aggregates the axes and renderer(s). – trashgod Nov 25 '19 at 08:49