Subscript in axis description

I wanted to know if an index can be used in an 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 index x in the string "a x [m / sΒ²]"? The subscript will be, for example, X₉

+4
source share
3 answers

Using the above approach here , you can specify the AttributedStringdesired axis for the label. For a value NumberAxiswith a name domainin the example below, values ​​are used TextAttributeto change SIZEand WEIGHTsome characters, second character indices, and superscripts.

String s = "ax [m/s2]";
AttributedString as = new AttributedString(s);
as.addAttribute(TextAttribute.SIZE, 24, 0, 2);
as.addAttribute(TextAttribute.SIZE, 16, 3, 9);
as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, 0, 2);
as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB, 1, 2);
as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 7, 8);
domain.setAttributedLabel(as);

image

+5
source

/ - Graphics2D ( Graphics2D.drawString). , "X\u2089" X₉. , , Unicode, java.

+1

jFreeChart, java , , :

final NumberAxis yaxY = new NumberAxis("a\u2093 [m/sΒ²]");

. http://www.fileformat.info/info/unicode/char/2093/index.htm

+1

Source: https://habr.com/ru/post/1583878/


All Articles