Excel VBA: plot multiple series using array data
I'm trying to plot three series on a chart table from the arraies.
ct is a chart table that is already created. The one-dimensional arraies A,B,C,x has the same length, as well as the same LBound and UBound.
Dim sr As Series
For Each sr In ct.SeriesCollection
sr.Delete
Next
With ct.SeriesCollection.NewSeries
.Name = "A"
.Values = a
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "B"
.Values = b
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "C"
.Values = c
.XValues = x
End With
However, there are no bars or lines on the graph after I run the macro. I can only see the tags "A", "B", "C" on the right side on the graph.
I'm a beginner for VBA. Any help will be appreciated.
excel vba excel-vba plot
add a comment |
I'm trying to plot three series on a chart table from the arraies.
ct is a chart table that is already created. The one-dimensional arraies A,B,C,x has the same length, as well as the same LBound and UBound.
Dim sr As Series
For Each sr In ct.SeriesCollection
sr.Delete
Next
With ct.SeriesCollection.NewSeries
.Name = "A"
.Values = a
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "B"
.Values = b
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "C"
.Values = c
.XValues = x
End With
However, there are no bars or lines on the graph after I run the macro. I can only see the tags "A", "B", "C" on the right side on the graph.
I'm a beginner for VBA. Any help will be appreciated.
excel vba excel-vba plot
Can you extend your code to the part where you definea,b,c,xarrays ?
– Display name
Nov 14 '18 at 4:25
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e..Values = Array(1, 2, 3, 4, 5, 6)
– Portland Runner
Nov 14 '18 at 4:29
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19
add a comment |
I'm trying to plot three series on a chart table from the arraies.
ct is a chart table that is already created. The one-dimensional arraies A,B,C,x has the same length, as well as the same LBound and UBound.
Dim sr As Series
For Each sr In ct.SeriesCollection
sr.Delete
Next
With ct.SeriesCollection.NewSeries
.Name = "A"
.Values = a
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "B"
.Values = b
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "C"
.Values = c
.XValues = x
End With
However, there are no bars or lines on the graph after I run the macro. I can only see the tags "A", "B", "C" on the right side on the graph.
I'm a beginner for VBA. Any help will be appreciated.
excel vba excel-vba plot
I'm trying to plot three series on a chart table from the arraies.
ct is a chart table that is already created. The one-dimensional arraies A,B,C,x has the same length, as well as the same LBound and UBound.
Dim sr As Series
For Each sr In ct.SeriesCollection
sr.Delete
Next
With ct.SeriesCollection.NewSeries
.Name = "A"
.Values = a
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "B"
.Values = b
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "C"
.Values = c
.XValues = x
End With
However, there are no bars or lines on the graph after I run the macro. I can only see the tags "A", "B", "C" on the right side on the graph.
I'm a beginner for VBA. Any help will be appreciated.
excel vba excel-vba plot
excel vba excel-vba plot
edited Nov 14 '18 at 7:55
Pᴇʜ
22k42750
22k42750
asked Nov 14 '18 at 3:07
Kangping YanKangping Yan
12
12
Can you extend your code to the part where you definea,b,c,xarrays ?
– Display name
Nov 14 '18 at 4:25
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e..Values = Array(1, 2, 3, 4, 5, 6)
– Portland Runner
Nov 14 '18 at 4:29
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19
add a comment |
Can you extend your code to the part where you definea,b,c,xarrays ?
– Display name
Nov 14 '18 at 4:25
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e..Values = Array(1, 2, 3, 4, 5, 6)
– Portland Runner
Nov 14 '18 at 4:29
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19
Can you extend your code to the part where you define
a,b,c,x arrays ?– Display name
Nov 14 '18 at 4:25
Can you extend your code to the part where you define
a,b,c,x arrays ?– Display name
Nov 14 '18 at 4:25
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e.
.Values = Array(1, 2, 3, 4, 5, 6)– Portland Runner
Nov 14 '18 at 4:29
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e.
.Values = Array(1, 2, 3, 4, 5, 6)– Portland Runner
Nov 14 '18 at 4:29
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19
add a comment |
1 Answer
1
active
oldest
votes
NewSeries empties the existing data in SeriesCollection every time. It works after I put those three NewSeries together before filling in the data.
With ct.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
.Item(1).Name = "A"
.Item(1).Values = a
.Item(1).XValues = x
.Item(2).Name = "B"
.Item(2).Values = b
.Item(2).XValues = x
.Item(3).Name = "C"
.Item(3).Values = c
.Item(3).XValues = x
End With
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292624%2fexcel-vba-plot-multiple-series-using-array-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
NewSeries empties the existing data in SeriesCollection every time. It works after I put those three NewSeries together before filling in the data.
With ct.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
.Item(1).Name = "A"
.Item(1).Values = a
.Item(1).XValues = x
.Item(2).Name = "B"
.Item(2).Values = b
.Item(2).XValues = x
.Item(3).Name = "C"
.Item(3).Values = c
.Item(3).XValues = x
End With
add a comment |
NewSeries empties the existing data in SeriesCollection every time. It works after I put those three NewSeries together before filling in the data.
With ct.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
.Item(1).Name = "A"
.Item(1).Values = a
.Item(1).XValues = x
.Item(2).Name = "B"
.Item(2).Values = b
.Item(2).XValues = x
.Item(3).Name = "C"
.Item(3).Values = c
.Item(3).XValues = x
End With
add a comment |
NewSeries empties the existing data in SeriesCollection every time. It works after I put those three NewSeries together before filling in the data.
With ct.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
.Item(1).Name = "A"
.Item(1).Values = a
.Item(1).XValues = x
.Item(2).Name = "B"
.Item(2).Values = b
.Item(2).XValues = x
.Item(3).Name = "C"
.Item(3).Values = c
.Item(3).XValues = x
End With
NewSeries empties the existing data in SeriesCollection every time. It works after I put those three NewSeries together before filling in the data.
With ct.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
.Item(1).Name = "A"
.Item(1).Values = a
.Item(1).XValues = x
.Item(2).Name = "B"
.Item(2).Values = b
.Item(2).XValues = x
.Item(3).Name = "C"
.Item(3).Values = c
.Item(3).XValues = x
End With
answered Nov 22 '18 at 3:06
Kangping YanKangping Yan
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292624%2fexcel-vba-plot-multiple-series-using-array-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you extend your code to the part where you define
a,b,c,xarrays ?– Display name
Nov 14 '18 at 4:25
Sounds like there may be no data in the array. If you hard code the array does it plot? i.e.
.Values = Array(1, 2, 3, 4, 5, 6)– Portland Runner
Nov 14 '18 at 4:29
The part of the code where I get a,b,c is quite long and a little bit complex. However, I use Debug.Print to print the data in a,b,c so I am sure I get the right numbers (I also check TypeName of elements in the arrays is double).
– Kangping Yan
Nov 14 '18 at 6:18
If I hard code the array to be 1,2,3..., there is still no data on the graph.
– Kangping Yan
Nov 14 '18 at 6:19