#1   Report Post  
Posted to microsoft.public.excel.programming
M H M H is offline
external usenet poster
 
Posts: 28
Default Chart Area

Hi all,
How could I retrieve the width and height of the plotarea of activechart
sheet (i.e.ActiveChart.PlotArea.Width (or .height))? I need these
numbers in order to plot several charts with identical dimensions
together in one single chart sheet, and they have to equally placed
along the width and height of the plot area.
Much thanks.


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Chart Area

Maurice,

I've never managed to do this absolutely perfectly thanks to the lack of
exactitude in the excel chart engine, but this gets very close. It assumes
you have a chart sheet set up with an existing chart on it, and have just
added another chart to the chart sheet.

If anyone can improve on this, please let me know directly. Thanks.

Sub AlignSubChartOnParent(chParent As Variant, chSubChart As Variant, _
Optional dSubHeight As Double)

'chParent is the chartsheet
'chSubChart is the sub chart
'aligns the sub chart underneath all the other charts on the page
'assumes no x-axis labels on the pre-existing charts
'kludges various items to make things work

Dim dPTotalWidth As Double
Dim dPCatHeight As Double
Dim dPCatWidth As Double
Dim dPValueLeft As Double
Dim lCounter As Long
Dim dAdjust As Double
Dim lVersion As Long
Dim shStart As Worksheet

Set shStart = ActiveSheet
lVersion = Val(Application.Version)

dAdjust = 0

If lVersion < 9 Then

chParent.Select
chSubChart.Parent.Select
chSubChart.Parent.Activate
chSubChart.PlotArea.Select

End If

'get parent dimensions
With chParent

dPTotalWidth = .ChartArea.Width
dPCatHeight = .Axes(xlValue).Top + .Axes(xlValue).Height
dPCatWidth = .Axes(xlCategory).Width
dPValueLeft = .Axes(xlValue).Left

End With

'get total height of all pre-existing charts on the sheet
For lCounter = 1 To chParent.ChartObjects.Count - 1
With chParent.ChartObjects(lCounter).Chart
dPCatHeight = dPCatHeight + .Axes(xlValue).Height
End With
Next lCounter

With chSubChart
.Parent.Left = 0
.Parent.Width = dPTotalWidth
If dSubHeight < 0 Then .Parent.Height = dSubHeight
dSubHeight = .Parent.Height

'set the plot area narrower than necessary then expand it later
With .PlotArea
.Top = 0
.Width = dPTotalWidth - 150
.Height = dSubHeight
End With

'try and get the left edges to line up
.PlotArea.Left = .PlotArea.Left + dPValueLeft - _
.Axes(xlValue).Left - .ChartArea.Left - dAdjust
'readjust the width
.PlotArea.Width = .PlotArea.Width + dPCatWidth - .Axes(xlCategory).Width
+ dAdjust

'readjust the left edge
.PlotArea.Left = .PlotArea.Left + dPValueLeft - .Axes(xlValue).Left -
..ChartArea.Left
.Parent.Top = dPCatHeight - .Axes(xlValue).Top - .ChartArea.Top - 0.5
End With
shStart.Select
End Sub

Robin Hammond
www.enhanceddatasystems.com


"M H" wrote in message
...
Hi all,
How could I retrieve the width and height of the plotarea of activechart
sheet (i.e.ActiveChart.PlotArea.Width (or .height))? I need these
numbers in order to plot several charts with identical dimensions
together in one single chart sheet, and they have to equally placed
along the width and height of the plot area.
Much thanks.


*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
M H M H is offline
external usenet poster
 
Posts: 28
Default Chart Area

Hi Robin,
Thanks for the code, but I couldn't run it when I pasted them into VBE.
It simply didn't show up in the macro list, even after corrected a
couple of typing errors.
Nice to meet you. BTW, are you also in HK?
Maurice



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Chart Area

Maurice,

try checking for messed up line breaks. Other than removing my error
handlers this is pasted as is from working code.
you too.
yes.

Robin Hammond
www.enhanceddatasystems.com

"M H" wrote in message
...
Hi Robin,
Thanks for the code, but I couldn't run it when I pasted them into VBE.
It simply didn't show up in the macro list, even after corrected a
couple of typing errors.
Nice to meet you. BTW, are you also in HK?
Maurice



*** Sent via Developersdex http://www.developersdex.com ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Chart Area

It won't show up in the macro list, because it requires parameters to be
passed, this stuff:

(chParent As Variant, chSubChart As Variant, _
Optional dSubHeight As Double)

Call it from within another sub or from the Immediate window, providing
values for the parameters.

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


M H wrote:

Hi Robin,
Thanks for the code, but I couldn't run it when I pasted them into VBE.
It simply didn't show up in the macro list, even after corrected a
couple of typing errors.
Nice to meet you. BTW, are you also in HK?
Maurice



*** Sent via Developersdex http://www.developersdex.com ***



  #6   Report Post  
Posted to microsoft.public.excel.programming
M H M H is offline
external usenet poster
 
Posts: 28
Default Chart Area

Thanks Jon. Does it mean something like:

Sub Test()
Call AlignSubChartOnParent("Chart1","Chart2",[55])
End Sub

I must have to read more from your website! It looks marvellous!

rgds,
Maurice

*** Sent via Developersdex http://www.developersdex.com ***
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Chart Area

Maurice -

Actually, the first entry must be a sheet object and the second a
chartobject object. It would be something like this (sorry, I can't wade
through the proposed code, it would take too many minutes):

Sub Test()
Call AlignSubChartOnParent(Sheets("Chart1"), _
Sheets("Chart1").chartobjects("Chart2"), 55)
End Sub

or

Sub Test()
AlignSubChartOnParent Sheets("Chart1"), _
Sheets("Chart1").chartobjects("Chart2"), 55
End Sub

It slipped my mind earlier, but I have a file you could download from my
website that handles alignment of charts:

http://peltiertech.com/Excel/Charts/...l#AlignChtDims

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


M H wrote:

Thanks Jon. Does it mean something like:

Sub Test()
Call AlignSubChartOnParent("Chart1","Chart2",[55])
End Sub

I must have to read more from your website! It looks marvellous!

rgds,
Maurice

*** Sent via Developersdex http://www.developersdex.com ***

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you show plot area only-no chart area SteveOz Charts and Charting in Excel 1 September 19th 07 10:06 AM
Stacked area and area chart combo [email protected] Charts and Charting in Excel 6 August 18th 06 02:30 PM
Resize plot area in a chart area Darlene Excel Discussion (Misc queries) 0 July 10th 06 02:50 PM
How to increase chart area without affecting plot area? [email protected] Charts and Charting in Excel 2 April 21st 06 09:05 PM
Resize chart area without resizing plot area Janwillem van Dijk Charts and Charting in Excel 2 August 2nd 05 01:52 AM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"