【发布时间】:2014-01-30 07:19:26
【问题描述】:
我只想添加有关图表的其他详细信息。我怎样才能在下面的图片中包含其他详细信息。
【问题讨论】:
-
@Radu Murzea,在我没有使用 JFreechart 之前。我只是希望解决方案可能与 XYTextAnnotation 有关。
-
意味着你需要添加标签是吗?表示将包含文本的标签是吗?
标签: java swing jfreechart
我只想添加有关图表的其他详细信息。我怎样才能在下面的图片中包含其他详细信息。
【问题讨论】:
标签: java swing jfreechart
final Marker start = new ValueMarker(3400000.0);
start.setPaint(Color.red);
start.setLabel("Current Value");
start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
plot.addRangeMarker(start);
34,00,000 是计数器值。根据需要设置计数器值。在 (x,y) 轴上。
【讨论】:
尝试注释(例如,XYDrawableAnnotation)。这是一个例子:
http://www.java2s.com/Code/Java/Chart/JFreeChartMarkerDemo1.htm
【讨论】:
您可以使用图形对象修改图表。 获取图表的图形对象:
下面是sn-p的代码:
// fetch chart as buffered image
BufferedImage image = chart.createBufferedImage(width, height);
// fetch graphics from the buffered image for perform modifications.
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setFont(g2.getFont().deriveFont(30f));
g2.setColor(Color.red);
g2.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
String str = "Test String";
float location_x = 200;
float location_y = 200;
// will draw string horizontally
TextUtilities.drawAlignedString(str, g2, location_x,
location_y, TextAnchor.CENTER_LEFT);
// will draw string Vertically
TextUtilities.drawRotatedString(str, g2, -Math.PI / 2,
location_x, location_y);
g2.dispose();
// generate png file from the modified buffered image
String path = "/sample/test.png";
try {
ImageIO.write(image, "png", new File(path));
} catch (IOException e) {
System.out.println("Error While Creating chart");
e.printStackTrace();
}
【讨论】: