eHow launches Android app: Get the best of eHow on the go.

How To

How to Create a Graph in VB

Contributor
By eHow Contributing Writer
(0 Ratings)

To create a graph in VB using data from an Excel sheet, you can use OLE's to join with the Excel Worksheet and fetch data for the graph. The data range for the graph will not change as you input new data into the Excel worksheet. The named range as the data source will be converted to cell addresses by VB to plot the graph.

The ActiveX controls also allow creation of scientific, engineering and general
graphs. It allows the user to control the appearance of the graph and add multiple axes as required. The other features of the graph that can be customized include grid lines, log-linear scales and legend tables. The graph can be plotted for discreet data points or continuous math-related functions.

Difficulty: Moderate
Instructions

Things You'll Need:

  • Visual Basic 6.0/5.0 version
  • MS Excel workbook
  • Knowledge of Visual Basic coding
  1. Step 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. Step 2

    Select the graph type like line, 3D or column. For plotting line graph, set chart type to "VtChChartType2dLine" and proceed.

  3. Step 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. Step 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. Step 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. Step 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. Step 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.

Tips & Warnings
  • To create a multi-dimensional graph, use an array of sizes three dimensional or more. Use spreadsheet or database to fill data into the array while plotting the graph. Changing the scale of the X axis has no visible effect on the graph. Set the color value of the graph through MS chart objects using long value of common dialog control.
  • Don't set subtitle to an empty string while creating the graph as it will only lead to hiding of the subtitle.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics