I wanted to know if it is possible to use subscript in axis description. I have the following code
XYItemRenderer lineYY = new StandardXYItemRenderer();
lineYY.setSeriesPaint(0, Color.BLUE);
lineYY.setSeriesVisibleInLegend(0,false);
final NumberAxis yaxY = new NumberAxis("ax [m/s²]");
yaxY.setRange(-11, 11);
yaxY.setAutoRangeIncludesZero(false);
XYPlot plotYY = new XYPlot(datasetY,null,yaxY, lineYY);
plotYY.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
Is there a way to subscript the x in the String "ax [m/s²]"? An subscript would be e.g. X₉
I am not sure about jFreeChart, but a pure java string could bear that, please try:
see: http://www.fileformat.info/info/unicode/char/2093/index.htm
You can try to use unicode values for the subscript/superscript - these should be respected by the Graphics2D rendering of the axis label (via Graphics2D.drawString method). For instance 'X\u2089' would be rendered similar to X₉. This is of course dependent on the Unicode subscript value existing as well as java supporting it.
Using the approach shown here, you can specify an
AttributedString
for the desired axis label. Given aNumberAxis
nameddomain
, the example below usesTextAttribute
values to alter theSIZE
andWEIGHT
of some characters, subscripts the second character and superscripts the exponent.