Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

more graphs 1

Status
Not open for further replies.

drewdaman

Programmer
Aug 5, 2003
302
CA
hello,

i am having a little trouble with some graphing.. in a previous post, i had posted this code to create a graph using arrays:

Code:
Sub graph(ByRef xvals() As Double, ByRef yvals() As Double, gsoffset As Double)
    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers

    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"


     
    Dim MyNewSrs As Series
    Set MyNewSrs = ActiveChart.SeriesCollection.NewSeries
    With MyNewSrs
        .Name = "Fred"
        .Values = yvals
        .XValues = xvals
        
    End With
End Sub

this works... sort of.. ie:

it creates a graph with teh same scale on the x and y axes. i want the scale on the x axis to go from 0 to 6000, incremements of 1000. this is fine. the problem is that it uses the same scale on the y axis.. i want the scale to go from 0 to 2 (possibly in increments of 0.2).. but it goes from 0 to 6000! so you can't really see the graph.. when i manually change teh scale for the y axis, the graph is fine.

i recorded a macro to change the scale.. and added that code to the method (after the last line of the above code- before the "end sub"). but it doesn't work either. actually, it worked once, and then never again!

this is the full code with the recorded macro lines added:

Code:
Sub graph(ByRef xvals() As Double, ByRef yvals() As Double, gsoffset As Double)
    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers

    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"


     
    Dim MyNewSrs As Series
    Set MyNewSrs = ActiveChart.SeriesCollection.NewSeries
    With MyNewSrs
        .Name = "Fred"
        .Values = yvals
        .XValues = xvals
        
    End With
    
    ActiveChart.Axes(xlValue).MajorGridlines.Select
    With ActiveChart.Axes(xlValue)
        .MinimumScaleIsAuto = 0
        .MaximumScale = gsoffset
        .MinorUnitIsAuto = True
        .MajorUnitIsAuto = True
        .Crosses = xlAutomatic
        .ReversePlotOrder = False
        .ScaleType = xlLinear
        .DisplayUnit = xlNone
    End With
End Sub


any ideas on how can i set the scale properly?

thanks!
 
yeah... i won't do that either.. i just have things hardcoded right now to make things a little easier.. so i dont' have to run my app every time i want to test this graphing bit.. i just have array loops like that now, and i will fix that.. but i assure you that is not the source of the current problem.

to refresh, the problem is that when i manually set values in the array (sub "la" pasted above) it works.. when i try to set more than 14 values in x and y arrays, it says it can't set the series. if i use fewer values, there is no problem.

thanks!
 


On what statement does the error occur?

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Code:
Sub graph(ByRef xvals() As Double, ByRef yvals() As Double, gsoffset As Double)
    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers

    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"

    'ActiveChart.Location xlLocationAsNewSheet, Name:="Sheet1"

     
    Dim MyNewSrs As Series
    Set MyNewSrs = ActiveChart.SeriesCollection.NewSeries
    With MyNewSrs
        '.Name = "Fred"
     [b]   .Values = yvals [/b]
        .XValues = xvals
    End With
    
    ActiveChart.Axes(xlValue).MajorGridlines.Select
    With ActiveChart.Axes(xlValue)
        .MinimumScale = 0
        .MaximumScale = gsoffset
        .MinorUnitIsAuto = True
        .MajorUnitIsAuto = True
        .Crosses = xlAutomatic
        .ReversePlotOrder = False
        .ScaleType = xlLinear
        .DisplayUnit = xlNone
    End With
    
    ActiveChart.Legend.Select
    Selection.Delete
End Sub

the error occurs on the line:
.Values = yvals


it occurs when yvals has more than 14 elements (an array indexed 0-13 is fine, but anything more makes it crash). but the really strange thing is that when i set the values manually (like in sub "la" that i posted above- 4-5 posts ago) it works.. i have cehcked the arrays in the debug window, and they have exactly the right values. in fact, the same code works if there are fewer than 14 elements in the array.

thanks for your replies and help with this issue skipvought!
 


Sorry. Can't seem to find the error.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
me neither :(

thanks for all the help anyways. i know you tried very hard!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top