+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Question How to resize plot areas so that graphs are uniform?

    Hi,

    I have many graphs (60+) and I have realised that, for whatever reason, some of the plot areas do not match in size despite the fact that the charts themselves have identical proportions.

    Is there any way to fairly quickly fix this? I pasted the charts directly into Word 2007 (i.e. so they are editable), but this was a while ago and they do not match the original ones anymore so I will need to edit them in Word.

    Any ideas?

    Thanks,

    SB

  2. #2
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to resize plot areas so that graphs are uniform?

    It doesn't need to be the fastest method possible, I would rather be able to achieve uniform dimension graphs than not at all! Unfortuantely I don't think I can use templates since the content of the graphs vary quite a lot.

    Thanks,

    SB

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    Do the charts have the same x and y axis labelling and how about the legend text?

    The plot area will be adjusted automatically to allow for variations in the size/amount of text.

    To force the sizing of the plotarea you would need code to loop through and adjust it's width/height/top/left.

    The code to loop and change is straight forward. What is not is what values to use. How do you know which dimensions should be used on all the charts?
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to resize plot areas so that graphs are uniform?

    Quote Originally Posted by Andy Pope View Post
    Do the charts have the same x and y axis labelling and how about the legend text?

    The plot area will be adjusted automatically to allow for variations in the size/amount of text.

    To force the sizing of the plotarea you would need code to loop through and adjust it's width/height/top/left.

    The code to loop and change is straight forward. What is not is what values to use. How do you know which dimensions should be used on all the charts?
    Thanks for the reply Andy. Almost all the charts have different x and y labels, also the legend position and contents varies considerably. I think I must have manually edited some of the plot areas at some point because they do not necessaraly match for otherwise identical charts. e.g:

    Example.

    These two empty graphs have the same dimensions when you select them, but the plot areas do not match.

    There is no exact answer as to what the plot area dimensions should be, but the outside dimensions are 7.5cm by 15.92cm. So essentially they just need to be uniform and fill most of the width of one sheet of A4 paper (15.92cm + 2x2.54cm margins) and most of the 7.5cm chart height. How would I go about writing the code?

    Thanks,

    SB
    Last edited by Silverbrook; 09-01-2009 at 09:22 AM.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    are the charts in excel or word.

    Can you post a file rather than a image.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to resize plot areas so that graphs are uniform?

    Quote Originally Posted by Andy Pope View Post
    are the charts in excel or word.

    Can you post a file rather than a image.
    The images are now in word. I have uploaded an example file showing what the problem is (the original file is rather large!).
    Attached Files Attached Files

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    This is a cheap and cheerful fix

    Code:
    Sub X()
        
        Dim objInLine As InlineShape
        Dim chtTemp As Chart
        Dim shpTemp As Shape
        
        For Each objInLine In ActiveDocument.InlineShapes
            If objInLine.HasChart Then
                Set chtTemp = objInLine.Chart
                With chtTemp.PlotArea
                    .Width = chtTemp.ChartArea.Width * 0.8
                    .Left = chtTemp.ChartArea.Width * 0.1
                    .Height = chtTemp.ChartArea.Height * 0.8
                    .Top = chtTemp.ChartArea.Height * 0.1
                End With
            End If
        Next
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  8. #8
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to resize plot areas so that graphs are uniform?

    Thanks for that Andy, your help is much appreciated. It works well, though I had trouble with one or two for some reason. Is there any way to make it so that it just resizes the currently selected graph?
    Last edited by shg; 09-03-2009 at 02:36 PM. Reason: deleted spurious quote

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    I can not get at the chart object via the Selection object.
    Nor can I identify what the selected item is called.

    If the code is missing some charts it maybe because they are in the shapes collection rather the InLineShapes collection.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: How to resize plot areas so that graphs are uniform?

    Thanks Andy. I suppose I could open a new word document and transfer the charts I want resizing and run the macro on those and then transfer them back. It certainly beats doing it manually with the ruler guides!!
    Last edited by shg; 09-03-2009 at 02:37 PM. Reason: deleted spurious quote

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    I took a break and had another bash.

    Try this on a selected chart

    Code:
    Sub X()
        
        Dim objInLine As InlineShape
        Dim chtTemp As Chart
        
        Set objInLine = ActiveWindow.Selection.InlineShapes(1)
        If Not objInLine Is Nothing Then
            If objInLine.HasChart Then
                Set chtTemp = objInLine.Chart
                With chtTemp.PlotArea
                    .Width = chtTemp.ChartArea.Width * 0.8
                    .Left = chtTemp.ChartArea.Width * 0.1
                    .Height = chtTemp.ChartArea.Height * 0.8
                    .Top = chtTemp.ChartArea.Height * 0.1
                End With
            End If
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  12. #12
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Thumbs up Re: How to resize plot areas so that graphs are uniform?

    Works perfectly, thanks! I figured out why a couple of them didn't resize 'correctly', it was because I had forgotten to change the font size of the y-axis to the same as the others, it made the end result slightly different but I have changed that now. Cheers Andy, the help has been massively appreciated!
    Last edited by shg; 09-03-2009 at 02:37 PM. Reason: deleted spurious quote

  13. #13
    Registered User
    Join Date
    08-31-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Red face Re: How to resize plot areas so that graphs are uniform?

    I've just had another thought (sorry!!) is there a way to modify the code so that it will position a legend in a particular place? Also would it be possible with horizontal/vertical axes titles?

  14. #14
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,137

    Re: How to resize plot areas so that graphs are uniform?

    Silverbrook, kindly don't quote whole posts. It's just clutter.

    Thanks.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: How to resize plot areas so that graphs are uniform?

    You just need to add the code to control the right part of the charts object model.

    Code:
    Sub X()
        
        Dim objInLine As InlineShape
        Dim chtTemp As Chart
        
        Set objInLine = ActiveWindow.Selection.InlineShapes(1)
        If Not objInLine Is Nothing Then
            If objInLine.HasChart Then
                Set chtTemp = objInLine.Chart
                With chtTemp.PlotArea
                    .Width = chtTemp.ChartArea.Width * 0.8
                    .Left = chtTemp.ChartArea.Width * 0.1
                    .Height = chtTemp.ChartArea.Height * 0.8
                    .Top = chtTemp.ChartArea.Height * 0.1
                End With
                If chtTemp.HasLegend Then
                    With chtTemp.Legend
                        .Left = 10
                        .Top = 10
                        .Width = 50
                        .Height = 50
                    End With
                End If
    ' X axis
                If chtTemp.Axes(1, 1).HasTitle Then
                    chtTemp.Axes(1, 1).AxisTitle.Left = chtTemp.PlotArea.InsideLeft
                End If
    ' Y axis            
                If chtTemp.Axes(2, 1).HasTitle Then
                    chtTemp.Axes(2, 1).AxisTitle.Top = chtTemp.PlotArea.InsideTop
                End If
                
            End If
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0