这是一个可以接受的java图形吗?
我需要在某人的类中绘制一些统计数据,该类扩展了JPanel
。现在计划使用paintComponent
和Graphics
类,如下所示:
public void paintComponent(Graphics g) {
super.paintComponent(g);
//create a rectangle to represent the outline of the graph
g.drawRect(300, 50, 400, 350);
//set up the datapoints
for(int i = 0; i < data.size(); i++) {
//put the datapoints where ever they need to go within this rectangle
g.drawOval(x, y, width, height);
}
}
这有什么可怕的原因吗?更重要的是,是否有一些很棒的、易于使用的图形库我可以使用但不知道
谢谢
# 1 楼答案
考虑JFreeChart
这里是the Javadoc for the JFreeChart
# 2 楼答案
在我看来,您的代码看起来不错,除了可能将x和y点放在
使椭圆居中
也可以考虑转换数据,以便绘制的点保持在图的域和范围的边界内。否则,矩形外可能有椭圆
您可能想查看JFreeChart的图形库