Axis描述中的下标

时间:2015-04-21 22:56:01

标签: java jfreechart subscription chartpanel

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

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

有没有办法在字符串“a x [m /s²]”中下标x?下标可以是例如X 9

3 个答案:

答案 0 :(得分:5)

使用显示here的方法,您可以为所需的轴标签指定AttributedString。给定名为NumberAxis的{​​{1}},下面的示例使用TextAttribute值来更改某些字符的domainSIZE,下标第二个字符并上标指数

WEIGHT

image

答案 1 :(得分:1)

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

答案 2 :(得分:1)

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

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

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