I like to make a histogram. With drawLine(), it's not really a problem for me, but when I try to do it with fillRect() the rectangles are going from top to bottom. I would like to paint the histogram looking similar to my histogram with drawLine().
Here is my code:
public void paint(Graphics g) {
super.paint(g);
int height = getHeight();
int width = getWidth();
int x =10;
haufigkeit=model.getMap();
for(int i = 1; i <= 45; i++) {
int y;
y = haufigkeit.get(i);
Color color = new Color(0, 0, (int)(150 + Math.random() * 100));
g.setColor(color);
// g.fillRect(x, 50, 10, y);
// g.drawLine(x, height - 50, x, height- y);
x+=20;
}
}
What needs to be changed?
解决方案
&