+ Reply to Thread
Results 1 to 2 of 2

Displaying Graphs on User Forms

Hybrid View

  1. #1
    Registered User
    Join Date
    07-09-2004
    Posts
    8

    Displaying Graphs on User Forms

    Morning Everyone,

    I am having a bit of trouble with something I would have imagined is fairly straightforward.

    I have creted a GUI using a user form in VB.

    I want this user form to display a graph based of the contents of the worksheet.

    I have found the chartspace icon on the toolbox and have added a chartspace to my form.

    Currently I have one button controlling the updating of this graph uising the code:

    Private Sub CommandButton1_Click()


    End Sub



    I am trinyg to use the Chartspace1.datasource property to assign a data source to the graph for plotting but I cannot find syntax anywhere that will work.

    Could someone give me an example of code that will plot the follwing data on a Form.

    range A1:Z1 on Sheet one when the button is clicked.

    Thanks in advance for your help.


    Mike

  2. #2
    Registered User
    Join Date
    07-09-2004
    Posts
    8

    Question

    Can anyone help with this

    I found this code but im not totally sure it will do what I want it to do?

    What do you guys reckon?

    ' Set the Spreadsheet component as the data source for the chart
    ChartSpace1.DataSource = Spreadsheet1

    'Get the constants for the Chart component

    dim c
    set c = ChartSpace1.Constants

    'Add the data to the chart and set the series names
    dim oSeries
    for i=1 to 5
    Set oSeries = oChart.SeriesCollection.Add
    oSeries.SetData c.chDimValues, 0, oSheet.Range(oSheet.Cells(2, i+1), oSheet.Cells(4, i+1)).Address
    oSeries.SetData c.chDimSeriesNames, 0, oSheet.Cells(1, i+1).Address
    next
    oChart.SetData c.chDimCategories, 0, "a2:a4"

    ' Format the chart to have a legend

    ChartSpace1.Charts(0).HasLegend = True

    ' Set the x-Axis to be percentages with 5% intervals
    oChart.Axes(c.chAxisPositionLeft).NumberFormat = "0%"
    oChart.Axes(c.chAxisPositionLeft).MajorUnit = 0.05

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1