+ Reply to Thread
Results 1 to 2 of 2

multiple y axis scales?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2007
    Posts
    3

    multiple y axis scales?

    Excel 2002

    Can charts be created with multiple y axis scales and a common x-axis scale?

    The VB Sub I have so far is this, but I would like to avoid Log Y axis and use a different scale for each series.
    Sub Create_Chart1()
    '
    ' Create_Chart1 Macro
    ' Create Chart of P3 - P7
    '
    
    '
        Charts.Add
        ActiveChart.ChartType = xlLine
        ActiveChart.PlotBy = xlColumns
        
        ' one series is present when chart is created
        'ActiveChart.SeriesCollection.Add Source:=Worksheets("CryoData").Range("B9:B129")
        ActiveChart.SeriesCollection.Add Source:=Worksheets("CryoData").Range("D9:D129")
        ActiveChart.SeriesCollection.Add Source:=Worksheets("CryoData").Range("E9:E129")
        ActiveChart.SeriesCollection.Add Source:=Worksheets("CryoData").Range("J9:J129")
        
        ' Set parameters and titles for series
        With ActiveChart.SeriesCollection(1)
            .Name = "P3"
            .XValues = Worksheets("CryoData").Range("A9:A129")
            .Values = Worksheets("CryoData").Range("B9:B129")
        End With
        With ActiveChart.SeriesCollection(2)
            .Name = "P5"
            .XValues = Worksheets("CryoData").Range("A9:A129")
            '.Values = Worksheets("CryoData").Range("D9:D129")
        End With
        With ActiveChart.SeriesCollection(3)
            .Name = "P7"
            .XValues = Worksheets("CryoData").Range("A9:A129")
            '.Values = Worksheets("CryoData").Range("E9:E129")
        End With
    
        With ActiveChart.SeriesCollection(4)
            .Name = "TC"
            .XValues = Worksheets("CryoData").Range("A9:A129")
            '.Values = Worksheets("CryoData").Range("J9:J129")
            .MarkerStyle = xlMarkerStyleCircle
        End With
    
        ' Chart name, location
        ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart1"
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "Chart of P3,P5,P7,TC"
            .Axes(xlCategory, xlPrimary).HasTitle = False
            .Axes(xlValue, xlPrimary).HasTitle = False
        End With
        
        
        ActiveChart.PlotArea.Select
        ActiveChart.Axes(xlValue).Select
        With ActiveChart.Axes(xlValue) ' scales are automatic and logarithmic due to wide range of values.
            .MinimumScaleIsAuto = True
            .MaximumScaleIsAuto = True
            .MinorUnitIsAuto = True
            .MajorUnitIsAuto = True
            .Crosses = xlAutomatic
            .ReversePlotOrder = False
            .ScaleType = xlLogarithmic ' make sure that all items are scaled so they can be read.
            .DisplayUnit = xlNone
        End With
        
        
    End Sub

  2. #2
    Registered User
    Join Date
    09-21-2007
    Posts
    3

    Question Can AxisGroup be used to define more than one YAxis?

    I've seen code that references xlPrimary. Is it possible to use xlSecondary to define a second Y axis? And if so, how does one associate a series with the secondary axis?
            With ActiveChart
            
                .HasTitle = True
                .ChartTitle.Characters.Text = "RUN " & trials 'Title of the graph
                .Axes(xlCategory, xlPrimary).HasTitle = True
                .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (0.1 sec)" 'x axis
                .Axes(xlValue, xlPrimary).HasTitle = True
                .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature (deg. C)" 'y axis
            End With
    I'd like to graph say 4 series in a chart, 2 on one Y scale and 2 on another , but all using the same X scale. Does xlPrimary and xlSecondary help me do that?

    Thanks,
    ww

+ 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