|
|
Title | Draw a simple histogram |
Keywords | histogram, graph |
Categories | Graphics |
|
|
Set a PictureBox's Scale properties so the values range from 0 to the number of histogram values horizontally and from 0 to the maximum data value vertically. Then for the ith bar, draw a box from (i - 1, 0) to (i, data_value(i)).
|
|
Private Sub DrawHistogram(ByVal pic As PictureBox, _
data_values() As Single, ByVal min_value As Single, _
ByVal max_value As Single)
Dim i As Integer
' Set convenient data bounds.
pic.ScaleLeft = LBound(data_values) - 1
pic.ScaleWidth = UBound(data_values) - _
LBound(data_values) + 1
pic.ScaleTop = max_value
pic.ScaleHeight = min_value - max_value
' Draw the data.
For i = LBound(data_values) To UBound(data_values)
pic.Line (i - 1, 0)-(i, data_values(i)), QBColor(i _
Mod 16), BF
Next i
End Sub
|
|
When the user clicks on the histogram, use the X coordinate to see which value is selected and display the value.
|
|
' Display this value.
Private Sub picHistogram_MouseDown(Button As Integer, Shift _
As Integer, X As Single, Y As Single)
Dim i As Integer
i = Int(X) + 1
MsgBox "Value " & i & " = " & m_DataValues(i)
End Sub
|
|
|
|
|
|