The Basics of Charting with the MS Chart Control - Getting into the plot area
(Page 4 of 4 )
Let's get some data into the plot area to see how this can be managed. The code shown in the next picture creates labels for the rows and the columns (Series). It also associates some data, albeit contrived to show how the data gets into the plot. Use another form in the same project, drop a chart control on the form, and to the form's load event, use the code shown in the next paragraph.
Private Sub Form_Load()
MSChart1.ToDefaults
With MSChart1
.ShowLegend = True
.Column = 1
.ColumnLabel = "red"
.Column = 2
.ColumnLabel = "green"
.Column = 3
.ColumnLabel = "blue"
.Column = 4
.ColumnLabel = "yellow"
.Column = 5
.ColumnLabel = "magenta"
.Row = 1
.RowLabel = "First"
.Row = 2
.RowLabel = "Second"
.Row = 3
.RowLabel = "Third"
.Row = 4
.RowLabel = "Four"
End With
For i = 1 To 4
With MSChart1
.Row = i
.Column = 1
.Data = 200 + 50 * i
.Column = 2
.Data = 300
.Column = 3
.Data = 400 - 10 * i
.Column = 4
.Data = 500 - 20 * i
.Column = 5
.Data = 100
End With
Next i
End Sub
When the above code is executed the chart is displayed as shown in the next picture. The code syntax is not intuitive, especially concerning the current row and current column. You need to define a column by using the variable 'Column'; confer a label on it using 'ColumnLabel'; and associate a 'data' with it using 'data'. This setting in the Properties window is especially confusing. What's more, the definition in design may override the run time values.
As for the data, the red bar increases; the blue and yellow bars decrease; and magenta and green stay constant. The chart appears to be automatically scaled. The title and foot note are left out.

Summary
This basic tutorial is a 101 level presentation of MS Chart Control. The material is very basic, but gives a good idea of how it is organized and how data may be plotted. Although individual data points have been associated with the rows and columns, the chart can be linked to data arrays as well as ADO and ActiveX Data Objects.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |