Hi! everyone. I am doing a bar chart project.
my project should looks like this:
[img]http://i6.tinypic.com/86gjn2e.jpg[/img]
the problem i have right now is that
i don't know how to draw the rectangle
in the right way.
my rectangle start to draw at the left top, how do i fix my code to make the rectangle draw start from the bottom?
Also, i don't know how to print data values inside each bar, centered horizontally and vertically
Anyone can give me any idea?
this is what i have done so far
[img]http://i8.tinypic.com/6nt35tw.jpg[/img]
Here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Blue As Brush = Brushes.Blue
Dim Red As Brush = Brushes.Red
Dim Purple As Brush = Brushes.Purple
Dim Green As Brush = Brushes.Green
Dim Yellow As Brush = Brushes.Yellow
Dim Black As Pen = New Pen(Color.Black, 3)
Dim total As Decimal
Dim data(5) As Decimal
Dim percentage(5) As Decimal
data(0) = Val(TextBox1.Text)
data(1) = Val(TextBox2.Text)
data(2) = Val(TextBox3.Text)
data(3) = Val(TextBox4.Text)
data(4) = Val(TextBox5.Text)
If data(0) = 0 And data(1) = 0 And data(2) = 0 Then Exit Sub
total = data(0) + data(1) + data(2) + data(3) + data(4)
percentage(0) = data(0) / total
percentage(1) = data(1) / total
percentage(2) = data(2) / total
percentage(3) = data(3) / total
percentage(4) = data(4) / total
Dim g As Graphics = PictureBox1.CreateGraphics()
g.Clear(Color.White)
g.FillRectangle(Blue, 30, 30, 30, 300 * percentage(0))
g.FillRectangle(Red, 65, 30, 30, 300 * percentage(1))
g.FillRectangle(Purple, 100, 30, 30, 300 * percentage(2))
g.FillRectangle(Green, 135, 30, 30, 300 * percentage(3))
g.FillRectangle(Yellow, 170, 30, 30, 300 * percentage(4))
g.Dispose()
End Sub
anyone can help me fix it? Thank you.