开发者

JFreeChart Vertical Label for IntervalMarker

开发者 https://www.devze.com 2023-03-27 09:49 出处:网络
I would like to rotate the label for the IntervalMarker: IntervalMarker im = new IntervalMarker(...); im.setLabel(\"LABEL\");

I would like to rotate the label for the IntervalMarker:

        IntervalMarker im = new IntervalMarker(...);
        im.setLabel("LABEL");
//      im.setLabelOffsetType(LengthAdjustmentType.EXPAND);
//      im.setLabelOffset(new RectangleInsets(10.0, 10.0, 10.0, 10.0)); 
//      im.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
        im.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        im.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        im.setPaint(new Color(208, 194, 214));

It didn't allow me to upload a picture, here is the link: http://i54.tinypic.com/5z40fs.png

I would like to have "LABEL" vertical开发者_JAVA百科, for better looks.

Thank you


I've found it easier to add Text Annotations to vertical markers for more control over their labels. Here's an example:

// vertical line marker and label
Marker updateMarker = new ValueMarker(dayOf, Color.black, dashedStroke, null, null, 1.0f);    
XYTextAnnotation updateLabel = new XYTextAnnotation("Update", dayOf - labelOffset, labelHeight);
updateLabel.setFont(new Font("Sans Serif", Font.BOLD, 10));
updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setRotationAngle(-3.14 / 2);
updateLabel.setPaint(Color.black);
plot.addDomainMarker(updateMarker, Layer.BACKGROUND);
plot.addAnnotation(updateLabel);

This rotation makes the label appear on the left side of the vertical marker line reading bottom-to-top. I use variables "labelOffset" and "labelHeight" to determine the exact position of the label in relation to the vertical line, but these could be set statically as well.


Rendering the marker's label is handled by the draw{Domain|Range}Marker() method of the plot's renderer using drawAlignedString(). You'd have to use drawRotatedString(), instead.


I couldn't find how to do this directly, but you can always put a rotated text Annotation in an appropriate place.

0

精彩评论

暂无评论...
验证码 换一张
取 消