Browse » Home
Tuesday, January 22, 2013
How to Create a Graph in VB
1. Use the VB view menu and open the code window. Select the form from drop-down combo box situated in the top left corner. You will need to place the MSChart control on the form in VB.
2. Select the graph type like line, 3D or column. For plotting line graph, set chart type to 'VtChChartType2dLine' and proceed.
3. Take an array which is two dimensional and store the X axis and Y axis values. Assign the array to the chart data property. The first two lines will help set subsets and points. This is for the amount of data that is required while plotting the graph.
4. Use a for-next loop to pass random data into the 2-D array or type in the static data manually to set up the elements of the array. Plot the graph properties to draw the X axis first, followed by the Y axis. Set the main title and subtitle along with the axis labels.
5. To access data from an Excel worksheet, use the get-object method to obtain reference to the workbook containing the worksheet. A reference needs to be set with the Excel objects library. This will help to populate the data in the array from the Workbook.
6. Set the Row and Column properties before returning the Data property for the Graph. Use the PointActivated event in VB to set the Data property. Change the scale of the graph by using ComboBox control and make changes to Y axis. Use the CommonDialog control's color property to apply different colors using the set method in the Graph.
7. After completing the coding based on the above mentioned steps use the Run option from the Start Menu to plot the graph. The customization options can be set through the Form properties window and helps to adjust plotting method, point labels, height, width and subset line types of the Graph.