我正在绘制三个时间序列,我想使用数字1,3和5作为XYLineAndShapeRenderer用于显示系列的实际形状。
即使你没有使用JFreeChart的经验,如果我能弄清楚如何做以下任何一项,我想我可以完成我的任务:
答案 0 :(得分:2)
您可以使用Font.createGlyphVector
和GlyphVector.getGlyphOutline
获取字形轮廓。
以下方法检索指定GlyphVector
的{{1}}并检索其轮廓,并在此过程中应用String
。
AffineTransform
默认情况下,返回的字形形状的字体大小为1,因此为static Shape[] getGlyphShapes(Font font, String strGlyphs, AffineTransform transform) {
FontRenderContext frc = new FontRenderContext(null, true, true);
GlyphVector glyphs = font.createGlyphVector(frc, strGlyphs);
int count = glyphs.getNumGlyphs();
Shape[] shapes = new Shape[count];
for (int i = 0; i < count; i ++) {
// get transformed glyph shape
GeneralPath path = (GeneralPath) glyphs.getGlyphOutline(i);
shapes[i] = path.createTransformedShape(transform);
}
return shapes;
}
。一个示例转换是:
AffineTransform
哪个字体应该大致居中每个字形(我认为你需要),字体大小为40.为了更准确的居中,你可以使用 AffineTransform transform = new AffineTransform();
transform.translate(-20, 20);
transform.scale(40, 40);
,通过GlyphMetrics
获得并计算你需要的确切翻译。