轴描述中的下标

Subscript in Axis description

我想知道是否可以在轴描述中使用下标。我有以下代码

    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);

有没有办法给字符串"ax [m/s²]"中的x下标?下标是例如X₉

您可以尝试为 subscript/superscript 使用 unicode 值 - 这些应该受到轴标签的 Graphics2D 渲染(通过 Graphics2D.drawString 方法)的尊重。例如 'X\u2089' 将呈现类似于 X₉。这当然取决于现有的 Unicode 下标值以及支持它的 java。

我不确定 jFreeChart,但是纯 java 字符串可以承受,请尝试:

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

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

使用显示的方法 here, you can specify an AttributedString for the desired axis label. Given a NumberAxis named domain, the example below uses TextAttribute 值来改变某些字符的 SIZEWEIGHT,下标第二个字符和上标指数。

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);