Mapping a numerical axis with a category axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sarahnac
Posts: 1
Joined: Fri Nov 13, 2015 3:33 pm
antibot: No, of course not.

Mapping a numerical axis with a category axis

Post by sarahnac » Fri Nov 13, 2015 3:39 pm

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

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Mapping a numerical axis with a category axis

Post by paradoxoff » Mon Nov 16, 2015 6:08 pm

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.

Locked