Results 1 to 11 of 11

Thread: [RESOLVED] Another Chart Problem

  1. #1

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Resolved [RESOLVED] Another Chart Problem

    Hey All,

    I have a function which creates charts from a specified range (always the "A" column of months, and one of many other columns). I allow only part of the entire column to be graphed (any part from 1-30 or 10-25), or the entire thing if the user so desires. This is all working great, except that the x-axis is not labeled correctly. For example if I only wanted to graph from months 4-10, the chart does correctly display the data for these months, except that the x-axis is labeled from 1-7 instead of 4-10. Anything I can do to force the graph to label the axis with this format instead of just always starting at 1? Here's my code if that is of help. Thanks much

    Code:
    If chkVolume.Value = True Then
        Dim chartVolume As Chart
        rangeName = "a" & startMonth & ":a" & endMonth & ", " 'Reset
        rangeName = rangeName & "j" & startMonth & ":j" & endMonth
        Call AddChartSheet("NNH3 Volume", rangeName, "LBS / AC N", graphStyle, chartVolume)
    End If
    End Sub
    
    
    Sub AddChartSheet(chartName As String, setRange As String, yTitle As String, graphStyle As Integer, chartOf As Chart)
       Set chartOf = Charts.Add
       For Each shtNext In Sheets
           If shtNext.Name = chartName Then 'Search/Delete charts w/ same name
                Application.DisplayAlerts = False 'No delete prompt
                Sheets(chartName).Delete
                Application.DisplayAlerts = True
           End If
       Next shtNext
       With chartOf
         .Name = chartName
          If graphStyle = 2 Then
            .ChartType = xlColumnClustered
          ElseIf graphStyle = 1 Then
            .ChartType = xlLine
          End If
          .SetSourceData Source:=Sheets("SOILSYM_MONTH").Range(setRange), _
            PlotBy:=xlColumns
          .HasTitle = True
          .ChartTitle.Text = chartName
          .Axes(xlCategory, xlPrimary).HasTitle = True
          .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
          .Axes(xlValue, xlPrimary).HasTitle = True
          .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = yTitle
          .SeriesCollection(1).Delete
          .HasLegend = False
       End With
    End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Another Chart Problem

    .SeriesCollection(1).Delete
    Why are you deleting the series collection?

    Also if I want the chart to pick up values for X axis from A1:A5 then I would do something like...

    .SeriesCollection(1).XValues = "=Sheet1!R1C1:R5C1"

    If the data needs to be picked up from A4:A10 the I would use something like...

    .SeriesCollection(1).XValues = "=Sheet1!R4C1:R10C1"

    and so on...

    ps: Replace "Sheet1" with the relevant sheet name...

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Another Chart Problem

    I delete Series1 because it just graphs the months in respect to the ... months... Its series 2 I am concerned about so I only display that.

    Also with your method of seriescollection, can I use seriescollection(1).Yvalues and choose what I want as my y-axis?

    thanks for the help kool

  4. #4

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Another Chart Problem

    and what is the difference b/w setsourcedata and seriescollection?

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Another Chart Problem

    Also with your method of seriescollection, can I use seriescollection(1).Yvalues and choose what I want as my y-axis?
    To choose values for Y-Axis use this

    vb Code:
    1. 'Change the range as appropriate...
    2. 'The range right now is B2:B9
    3.  
    4. .SeriesCollection(1).Values = "=Sheet1!R2C2:R9C2"

    what is the difference b/w setsourcedata and seriescollection?
    SetSourceData sets the source data range for the chart.

    SeriesCollection returns an object that represents either a single series (a Series object) or a collection of all the series (a SeriesCollection collection) in the chart or chart group.

    Using SeriesCllection gives you more control over the way you want to display your data in the chart

    Hope this helps...

    [edit]

    I delete Series1 because it just graphs the months in respect to the ... months... Its series 2 I am concerned about so I only display that.
    Try using

    .SeriesCollection(1).XValues

    and

    .SeriesCollection(1).Values

    together in lieu of

    .SeriesCollection(1).Delete
    Last edited by Siddharth Rout; Mar 29th, 2007 at 05:15 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Another Chart Problem

    Great thanks again koolsid. I will try implementing SeriesCollection and see if that works.

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Another Chart Problem

    just edited the above post (added new comments)
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Another Chart Problem

    I'm now getting an error, saying "seriescollection method of _chart object failed ...

    Code:
    Sub AddChartSheet(chartName As String, setRange As String, yTitle As String, graphStyle As Integer, chartOf As Chart)
       Set chartOf = Charts.Add
       For Each shtNext In Sheets
           If shtNext.Name = chartName Then 'Search/Delete charts w/ same name
                Application.DisplayAlerts = False 'No delete prompt
                Sheets(chartName).Delete
                Application.DisplayAlerts = True
           End If
       Next shtNext
       With chartOf
         .Name = chartName
          If graphStyle = 2 Then
            .ChartType = xlColumnClustered
          ElseIf graphStyle = 1 Then
            .ChartType = xlLine
          End If
          '.SetSourceData Source:=Sheets("SOILSYM_MONTH").Range(setRange), _
            'PlotBy:=xlColumns
            .SeriesCollection.NewSeries
            .SeriesCollection(1).XValues = "=SheetName!R4C1:R14C1" 'failing here
            .SeriesCollection(1).Values = "=SheetName!R4C7:R14C7"
            
          .HasTitle = True
          .ChartTitle.Text = chartName
          .Axes(xlCategory, xlPrimary).HasTitle = True
          .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
          .Axes(xlValue, xlPrimary).HasTitle = True
          .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = yTitle
          '.SeriesCollection(1).Delete
          .HasLegend = False
       End With
    End Sub
    Last edited by pgag45; Mar 30th, 2007 at 04:39 PM.

  9. #9

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: Another Chart Problem

    Nevermind got it working.. thanks

  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Another Chart Problem

    HI

    "=SheetName!R4C1:R14C1"

    was that because of

    "=" & SheetName & "!R4C1:R14C1" ?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Another Chart Problem

    yes

    but thanks for the continuing help man.

Posting Permissions

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



Click Here to Expand Forum to Full Width