Subscript in Axis description

前端 未结 3 1858
暗喜
暗喜 2020-12-11 21:08

I wanted to know if it is possible to use subscript in axis description. I have the following code

    XYItemRenderer lineYY = new StandardXYItemRenderer();
         


        
3条回答
  •  北海茫月
    2020-12-11 22:10

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

    image

提交回复
热议问题