Axis描述中的下标 [英] Subscript in Axis description

查看:198
本文介绍了Axis描述中的下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

有没有办法在字符串a x 中下标x [米/秒²]?下标可以是例如X₉

Is there a way to subscript the x in the String "ax [m/s²]"? An subscript would be e.g. X₉

推荐答案

使用显示的方法此处,您可以指定 AttributedString ,用于所需的轴标签。给定 NumberAxis 名为,下面的示例使用 TextAttribute 值可以改变<$某些字符的c $ c> SIZE 和 WEIGHT ,下标第二个字符并上标指数。

Using the approach shown here, you can specify an AttributedString for the desired axis label. Given a NumberAxis named domain, the example below uses TextAttribute values to alter the SIZE and WEIGHT of some characters, subscripts the second character and superscripts the exponent.

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

这篇关于Axis描述中的下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆