Java 我可以使用数字作为形状图标,用于在JFreeChart中的XYPlot上显示点吗?
我正在绘制三个时间序列,我想使用数字1、3和5作为XYLineAndShapeRenderer用于显示序列的实际形状 即使您没有使用JFreeChart的经验,但如果我能想出如何执行以下任一操作,我认为我可以完成我的任务:Java 我可以使用数字作为形状图标,用于在JFreeChart中的XYPlot上显示点吗?,java,awt,shape,glyph,imageicon,Java,Awt,Shape,Glyph,Imageicon,我正在绘制三个时间序列,我想使用数字1、3和5作为XYLineAndShapeRenderer用于显示序列的实际形状 即使您没有使用JFreeChart的经验,但如果我能想出如何执行以下任一操作,我认为我可以完成我的任务: 将字符/字形转换为java.awt.Shape 将字符/图示符转换为图像图标 您可以使用Font.createGlyphVector和GlyphVector.getGlyphOutline获取字形轮廓 下面的方法为指定的字符串检索字形向量,并在过程中应用仿射变换,检索其轮廓
您可以使用
Font.createGlyphVector
和GlyphVector.getGlyphOutline
获取字形轮廓
下面的方法为指定的字符串
检索字形向量
,并在过程中应用仿射变换
,检索其轮廓
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;
}
它应该大致将每个字形(我想您需要)居中,字体大小为40。为了更精确地居中,您可以使用通过GlyphVector.getGlyphMetric
获得的GlyphMetrics
,并计算所需的精确平移
AffineTransform transform = new AffineTransform();
transform.translate(-20, 20);
transform.scale(40, 40);