Does any one know how to create a bar and line graph separately from any array of numbers?

For example int test[] ={0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,300};

To be simple I was trying to draw a bar graph by using
g.drawRect(0, 10, 2, 0);
g.drawRect(20, 20, 2, 20);
g.drawRect(40, 30, 2, 40);

This draws the bars out of rectangle, but they are not leveled.

I tried making each of the Ys the same:

g.drawRect(0, 10, 2, 0);
g.drawRect(20, 10, 2, 20);
g.drawRect(40, 10, 2, 40);

This resulted in the bars (rectangles) being on the same line but appearing to be upside down.

As far as quadrants in geometry, it looks as though I'm drawing to the wrong one.