+ Reply to Thread
Results 1 to 5 of 5

Excel chart Y axis v's series

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Excel chart Y axis v's series

    Hi,

    Is there a way to force Excel to keep a consistent format for charts. I have a clustered bar chart that has three bars that I am after. With the data that I have, if there is three or more batches, then the chart comes out correctly with the three columns (see Correct image) if there is less than 3, excel swaps the Y axis for the series data (see incorrect image) which is now out of my jurisdiction as it is all generated from an excel VBA script, not done manually.

    What do I need to add to get these bits correct.

    Kind regards

    Rob

    Correct.PNGIncorrect.PNG

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,357

    Re: Excel chart Y axis v's series

    Can I assume that this is about chart creation, and not a situation where Excel is "changing" from rows to columns after the chart is created? Issues like this seem to be very common in the "chart creation" process, but should not occur in a pre-existing chart.

    One of the things I miss from the pre-2007 versions of Excel is the chart wizard. Using the chart wizard, you could specify "data in rows" or "data in columns" during the process of creating the charts. Since 2007, Excel has taken a "let's get the chart created, even if it is wrong, then fix it after it is created" approach. As common as this particular issue is (Excel guess row vs. column incorrectly), they even included a "button" on the Chart->Design tab for "switch row/column". If I understand the concern you are having, it should be as easy as 1) create the chart like you are currently doing, then 2) Click on "Switch row/column" command.

    Does that help?
    Last edited by MrShorty; 06-17-2015 at 11:25 AM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Excel chart Y axis v's series

    Absolutely spot on MrShorty sir, that solved my problem. For others that may find this, here is the subroutine that creates a chart from dynamic data as I have found that the order definitely does matter.
    Sub History_Chart()
        Dim hData As Range
        Dim hChart As Shape
        
        Set hData = Range(BatchSearch.Offset(0, 1), BatchSearch.End(xlToRight)).Resize(5)
        With inspHist.ChartObjects.Add(Left:=100, Width:=375, Top:=75, Height:=225)
            With .Chart
                .ChartType = xlColumnClustered
                .SetSourceData Source:=hData
                .PlotBy = xlRows
                .Parent.Name = "Inspection_Chart"
            End With
        End With
        inspHist.Visible = xlSheetVisible
        inspHist.Select
    End Sub

    BatchSearch is a globally defined "Range" Variable declared at the beginning of the module.

    Kind regards
    Rob

  4. #4
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Re: Excel chart Y axis v's series

    Hi, yes this is indeed about Chart creation. This part of the macro creates a chart of requested part number batch dates that appears on a sheet with a back button on it. when back is pressed, the chart itself is deleted. So it is always only a temporary thing. It was my work around for not knowing how to produce a pop up window from a user form. It works very well, except for this issue, which as you may have guessed by now cannot be fixed manually, it has to be done at the point of creation.

    Is this possible?

    Kind regards
    Rob

    P.S. It is not the X and Y axis that is being switched, it is the Y axis and the Series that is being switched. And I am after some VBA code to correct this.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,357

    Re: Excel chart Y axis v's series

    If I understand correctly, recognize that switching x/y axes is different from switching "chart by row" vs "chart by column". In your first picture, the data appear to be plotted by rows, where your second picture shows data plotted by columns. Switching between the two pictures should be as simple as pressing the "switch rows/columns" button.

    Recording a quick macro while commanding the switch rows/columns button indicates that the property in question is the chart.plotby property (https://msdn.microsoft.com/en-us/lib.../ff822363.aspx ). In VBA, it seems like controlling this should be as easy as adding a thischart.PlotBy=xlrows statement to the code after the chart is created, assuming that the first picture is the correct one.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 04-23-2015, 11:21 AM
  2. [SOLVED] Surface Chart Depth Axis showing all Data Series' on top of each other (Excel 2007)
    By enginezzz in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 02-26-2013, 11:22 AM
  3. RE: Moving X Axis and Series Values in chart
    By statsfun in forum Excel General
    Replies: 0
    Last Post: 09-13-2012, 11:41 AM
  4. Self expanding chart (incorporating new series to both the and x axis)
    By a.mack123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-18-2011, 06:52 AM
  5. Chart w/x axis showing different series
    By JIBG in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-23-2007, 09:12 PM

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.6.0 RC 1