Thread: category Axis
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.charting
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default category Axis

Mark -

Far as I know, there's no limit to the levels of "." you can use, as long as
the OM goes that deep.

I generally use Set Blah = New Object/With Blah, unless it's a small little
thing like this. The variable Blah gets reused in the loop (adding a set of
series), then soon goes out of scope when the function or sub ends.

I'm not familiar with the .Net stuff. I've been told it's okay to let VB/VBA
set everything to nothing internally when a procedure ends.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Mark Burns" wrote in message
...
Jon,

Yo! DUDE!
...Wow!
I wish I'd known to come ask you all these questions a few days ago!
You are a veritable FOUNT of most useful knowledge.

"..AxisGoup"? I never know you could stack the . operators in VBA as you
can
in DOS filespecs...and I've been doing VB/VBA for a LONG TIME too. Where'd
I
miss that little tidbit at? (is .. the limit, or can it stack to ... and
....
too? nevermind I'll find out. Dang but I see how THAT could be trouble
too.)

Oh, you do know that if you do that
"With ActiveChart.SeriesCollection.NewSeries"
trick with some COM objects, (creating the new object instance on the WITH
line, I mean) you _can_ create yourself some serious COM reference-count
problems and sometimes leave yourself with seemingly "hung"
applications/sessions...? <explanation follows - primarily for the
lurkers
(The reason for that is the With construct creates a "phantom" object
reference in memory, but the pointer to it gets lost at the End With. The
hung COM object problem arises if that object instance holds referencing
pointers to itself or other COM class instances within its application -
or
worse yet, if other instances manage to hold references to it when it goes
out of scope and VB/VBA "loses" it after the End With - then the object
stays
alive in memory - meaning no Terminate Event fires - because its COM
reference count stays 0...)

It is *always* recommended to do this instead:
Set oSomeVarHere = <New WhateverObjectType
(or <any object/method which results in a new object instance here i.e.
".NewSeries")
With oSomeVarHere
...
<Do stuff with . object properties/methods here
...
End With
...
oSomeVarHere.Dispose() 'if you're trying to follow .NET iDisposable
Semantics
set oSomeVarHere = Nothing 'assures destruction of the COM object...

...especially if the .Dispose() call makes sure that the oSomeVarHere
instance releases all its internal reference to other objects.
<end of explanation for benefit of lurkers

ps. FWIW, I've found that following the .Net iDisposable semantics is a
good
idea even in VB6/VBA coding scenarios...it tends to make you a more
careful
object/class instance consumer and help you avoid LOTS of potential COM
headaches in the bargain - primarily because it makes you THINK about your
object destruction calls in your code designs.

"Jon Peltier" wrote:

Here are some pointers:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

Use the ChartObjects.Add method to add a chart to the worksheet
http://peltiertech.com/Excel/ChartsH....html#addchart

Use the SeriesCollection.NewSeries method to add a series to the chart:
http://peltiertech.com/Excel/ChartsH...html#addseries

Assign the data, series type, and axis group:

Sub AddNewSeries()
With ActiveChart.SeriesCollection.NewSeries
.Name = "Fred"
.Values = "=Sheet1!Y_Range"
.XValues = Array(1, 2, 3) .ChartType = xlLine
..AxisGroup = xlPrimary
End With
End Sub
I use .Values and .XValues, because most of my charts are XY charts, and
each series has distinct X and Y values in this chart type. For
consistency
I use the same approach for all charts.For a list of chart types, go to
the
VB Editor, choose Object Browser from the View menu, select Series in the
list of Classes, and select ChartType in the list of Members of 'Series'.
At
the bottom it says Property ChartType As XlChartTypewhere XlChartType is
a
hyperlink. Click on this to get a list of chart type constants.-
Jon-------Jon Peltier, Microsoft Excel MVPTutorials and Custom
SolutionsPeltier Technical Services, Inc. - http://PeltierTech.com_______
"Mark Burns" wrote in message
...
Jon,

1st: Thanks for the feedback! I appreciate your time and insights.

Ok, so what are the "general rules" for "making a regular chart" then?
i.e.: when/how do you add axes -vs- series...?
How (and when, sequence-of-operations-wise) do you tell the charting
component what chart type to draw / what to do with each series...?
is there a list of valid chart or series format types around anywhere
(probably asking alot, I know)...

Is there a particular reason you don't assign the .categorynames to the
xlCategory, xlPrimary axis yourself - or is it more just a personal
preference thing? (or is it that .XYvalues does the same thing
behind-the-scenes?)


"Jon Peltier" wrote:

It would be easier to make a regular chart, not a built-in custom
type,
and
assign the chart type and axis group to each series as it is added.
The
built-in custom types ignore what you say and place the first half or
so
into one style and the last half or so into the other.

Well...that 'splains some of that apparent oddnesss, then.
I didn't have enough time to figure out what things that
assigning/reassigning the charttype did or didn't step on, either.

Also, I generally ignore the .CategoryNames in favor of using the same
range
as .XValues for all series.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Mark Burns" wrote in message
...
I am building an Column-Line on 2 Axes chart via Automation from
Access.
It is basically working, but for some reason, I can't get it to set
the
Category (x) axis labels now.
I am now getting a 1004 "unable to set the CategoryNames property of
the
Axis class" error message.
I am setting it with:
Set oXLCAx = oXLC.Axes(xlCategory, xlPrimary)
With oXLCAx
.CategoryNames = xlWS.Range(oXAxis.RangeAddress)
<...snip...
end with

Current, my oXAxis.RangeAddress object is holding the following
value:
"[Sheet1]DatarptCorpIncidentsBarsAndLine!$B$2:$B$14,
[Sheet1]DatarptCorpIncidentsBarsAndLine!$B$26,
[Sheet1]DatarptCorpIncidentsBarsAndLine!$B$28,
[Sheet1]DatarptCorpIncidentsBarsAndLine!$B$30:$B$31"

Does it have a problem accepting a non-contiguous address range?
I have previously defines 8 series (4 each on the primary and
secondary
axes)

...or have I made some other sort of sequence error in creating the
seriescollections? (I found that I had to make a 4 primary series,
and
add
the 4 secondary ones, doing it pair by pair did not seem to work
properly
and
the series' wound up getting mixed up on the wrong axes somehow
(despite
putting the .axisgroup = xlprimary or .axisgroup = xlsecondary on
each
series
object)!?

(I also tried to set the .XValues when creating/adding the series
with
my
oXAxis.Rangeaddress value, and it would not take that either...=1004
error.)

Any suggestions?