绘制直方图
问题描述:
我想画一个JPEG系数直方图绘制直方图
//coeff[] is the coefficients array
int hist[]=new int[25];
for(int i=0;i<coeff.length;i++)
hist[coeff[i]]++;
现在我想提请HIST阵列状条形图柱状图,但我不知道有什么功能呢吗? 在此先感谢
答
当你有一个JFrame或类似的东西,你可以重写paint(Graphics g)方法。然后,你就可以绘制条是这样的:
@Override
public void paint(Graphics g)
{
super.paint(g);
final int barwidth = 20;
for(int i=0;i<25;i++){
g.fillRect(i*barwidth , 0, barwidth , hist[i]*10);
}
}
这里是一个JLabel的例子:
class Histogram extends JLabel{
//... make hist visible for this class
@override
protected void paintComponent(Graphics g){
super.paintComponent(g);
final int BAR_WIDTH = 20;
final int X_POSITION = 0;
final int Y_POSITION = 200;
for(int i=0;i<25;i++){
g.fillRect(X_POSITION +i*BARWIDTH , Y_POSITION , BAR_WIDTH , -hist[i]*10);
}
}
}
然后,你可以把它添加到你的主机是这样的:
Histogram histogram = new Histogram();
add(histogram);
当这回答你的问题请标记线索,谢谢。
看起来你甚至没有首先谷歌搜索。 – 2012-03-29 18:58:58
我看着JFreeChart,但不知道如何将数组添加为数据集? – muhannad 2012-03-29 19:04:10