|
-
Mar 29th, 2007, 04:28 PM
#1
Thread Starter
Hyperactive Member
[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
-
Mar 29th, 2007, 04:42 PM
#2
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
-
Mar 29th, 2007, 04:56 PM
#3
Thread Starter
Hyperactive Member
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
-
Mar 29th, 2007, 05:00 PM
#4
Thread Starter
Hyperactive Member
Re: Another Chart Problem
and what is the difference b/w setsourcedata and seriescollection?
-
Mar 29th, 2007, 05:12 PM
#5
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:
'Change the range as appropriate...
'The range right now is B2:B9
.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
-
Mar 29th, 2007, 05:14 PM
#6
Thread Starter
Hyperactive Member
Re: Another Chart Problem
Great thanks again koolsid. I will try implementing SeriesCollection and see if that works.
-
Mar 29th, 2007, 05:16 PM
#7
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
-
Mar 30th, 2007, 04:32 PM
#8
Thread Starter
Hyperactive Member
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.
-
Mar 30th, 2007, 04:40 PM
#9
Thread Starter
Hyperactive Member
Re: Another Chart Problem
Nevermind got it working.. thanks
-
Mar 30th, 2007, 04:43 PM
#10
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
-
Mar 30th, 2007, 04:45 PM
#11
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|