gpt4 book ai didi

java - 我可以使用数字作为形状图标来显示 JFreeChart 中 XYPlot 上的点吗?

转载 作者:行者123 更新时间:2023-11-30 04:49:32 26 4
gpt4 key购买 nike

我正在绘制三个时间序列,我想使用数字 1、3 和 5 作为 XYLineAndShapeRenderer 用于显示该系列的实际形状。

即使您没有使用 JFreeChart 的经验,如果我能弄清楚如何执行以下任何操作,我想我也可以完成我的任务:

  1. 将字符/字形转换为 java.awt.Shape
  2. 将字符/字形转换为 ImageIcon

最佳答案

您可以使用 Font.createGlyphVectorGlyphVector.getGlyphOutline 获取字形轮廓。

下面的方法检索指定 StringGlyphVector 并检索其轮廓,在此过程中应用 AffineTransform

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;

}

默认情况下,返回的字形形状的字体大小为 1,因此是AffineTransform。一个示例转换是:

            AffineTransform transform = new AffineTransform();
transform.translate(-20, 20);
transform.scale(40, 40);

这应该将每个字形(我认为您需要)大致居中,字体大小为 40。为了更准确地居中,您可以使用通过 GlyphVector 获得的 GlyphMetrics。 getGlyphMetric 并计算您需要的精确翻译。

关于java - 我可以使用数字作为形状图标来显示 JFreeChart 中 XYPlot 上的点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10150833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com