Hello all,
Is it possible, on a scatter chart plot, to custom the x-axis?
To be more explicit : I have a numerical axis, but i need to display it in an other way (The value from 1,5 to 4,5 need to be displayed with one tick in the middle called "N°1" by example). Is it possible to create this "virtual" category axis?
Many thanks!
Sarah
Mapping a numerical axis with a category axis
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Mapping a numerical axis with a category axis
Hide the tick marks of the axis completely, and use a custom XYAnnotation to draw the special ticks. You could derive your annotation from one of a set of new annotation classes that I wrote some time ago(link).
For your case, extend XYDomainIntervalAnnotation and overwrite the draw Method. In the overridden draw method, instead of creating a rectangular path, you can simply create a Line2D between startLine.getX1(), startLine.getY1() and endLine.getX1(), endLine.getY1(). In order to place the label for the annotation (which will be the tick label for the region) in a central arrangement to the region, call setLabelTextAnchor(TextAnchor.TOP_CENTER) and setLabelAnchor(RectangleAnchor.BOTTOM) on your annotation.
For your case, extend XYDomainIntervalAnnotation and overwrite the draw Method. In the overridden draw method, instead of creating a rectangular path, you can simply create a Line2D between startLine.getX1(), startLine.getY1() and endLine.getX1(), endLine.getY1(). In order to place the label for the annotation (which will be the tick label for the region) in a central arrangement to the region, call setLabelTextAnchor(TextAnchor.TOP_CENTER) and setLabelAnchor(RectangleAnchor.BOTTOM) on your annotation.