+ Reply to Thread
Results 1 to 28 of 28

Rectangle graph

Hybrid View

  1. #1
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,488

    Re: Rectangle graph

    Sub VariWidthColumns()
    '
        Dim myChart As Chart
        Dim rngData As Range
        Dim lngIndex As Long
        Dim zz As Series
        
        Set rngData = Range("A1:N15")
        Set myChart = ActiveSheet.ChartObjects.Add(650, 30, 620, 410).Chart
       
        With myChart
            .ChartType = xlArea
            .SetSourceData Source:=rngData
        
            For lngIndex = 1 To 4
                With .SeriesCollection(lngIndex)
                    With .Format.Line
                        .Weight = 1
                        .Visible = True
                        .ForeColor.RGB = 0 ' black
                    End With
                End With
            Next
        
            With .SeriesCollection(5)
                .ChartType = xlLine
                With .Format.Line
                    .Weight = 1
                    .Visible = True
                    .ForeColor.RGB = 255 ' red
                    .DashStyle = msoLineDash
                End With
                With .Points(1)
                    .HasDataLabel = True
                    With .DataLabel
                        .ShowValue = False
                        .ShowSeriesName = True
                        .ShowCategoryName = False
                        .Position = xlLabelPositionRight
                        .Font.Bold = True
                        .Font.Size = 10
                        .Font.Color = vbRed
                    End With
                End With
            End With
        
            For lngIndex = 6 To 13                  '5 to 12
                With .SeriesCollection(lngIndex)
                    .ChartType = xlLine
                    .AxisGroup = 2
                    .HasDataLabels = True
                    With .DataLabels
                        .ShowValue = False
                        .ShowSeriesName = True
                        .ShowCategoryName = False
                        .Position = xlLabelPositionAbove
                        .Font.Bold = True
                        .Font.Size = 7.5
                    End With
                End With
            Next
            
            With .Axes(xlCategory)
                .CategoryType = xlTimeScale
                .MaximumScale = 100
                .MajorUnit = 10
                .MinorUnit = 5
                .MinorTickMark = xlOutside
                .AxisBetweenCategories = False
                .Format.Line.Weight = 2.25
                .HasTitle = True
                .AxisTitle.Text = "Share of total, %"
                With .TickLabels
                     .NumberFormat = "# ##0"
                     .Font.Bold = True
                End With
            End With
        
            With myChart.Axes(xlValue, xlPrimary)
                .HasMajorGridlines = True
                .MajorGridlines.Border.LineStyle = xlDash
                .MinimumScale = 0
                .MaximumScale = 10
                .MajorUnit = 1
                .MinorUnit = 0.5
                .MinorTickMark = xlOutside
                .Format.Line.Weight = 2.25
                With .TickLabels
                     .NumberFormat = "# ##0"
                     .Font.Bold = True
                End With
                .HasTitle = True
                .AxisTitle.Text = "Value Axis"
            End With
        
            With myChart.Axes(xlValue, xlSecondary)
                .HasMajorGridlines = True
                .MajorGridlines.Border.LineStyle = x1Dash
                .MinimumScale = 0
                .MaximumScale = 10
                .MajorUnit = 1
                .MinorUnit = 0.5
                .MinorTickMark = xlOutside
                .Format.Line.Weight = 2.25
                With .TickLabels
                     .NumberFormat = "# ##0"
                     .Font.Bold = True
                End With
                .HasTitle = False
                '.AxisTitle.Text = "Value Axis"
            End With
        
            .DisplayBlanksAs = xlNotPlotted
            .Legend.Delete
        End With
        
    End Sub
    you has x1Dash rather than xlDash. (1 one rather than l L)
    you need to change chart type of 5th series to line
    those new series data labels are at the top of the chart
    Cheers
    Andy
    www.andypope.info

  2. #2
    Forum Contributor
    Join Date
    12-30-2013
    Location
    Falun, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Rectangle graph

    Hi Andy,

    I tried to extend the labels with another series (AAAA, BBBB, CCCC, and DDDD), but then the macro does not seem to function at all. Have you any explanation to this?

    Besides, the color of the dotted line representing "average" is still blue, even if the code indicates that the line should be red. Why?

    Kind regards,

    Jan
    Attached Files Attached Files

+ 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. Puzzling grey rectangle
    By norgro in forum Excel General
    Replies: 10
    Last Post: 12-22-2012, 02:51 AM
  2. Rectangle with curved corners
    By Zone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2006, 02:40 PM
  3. Delete a rectangle using a macro
    By cailotto@sbcglobal.net in forum Excel General
    Replies: 2
    Last Post: 09-29-2005, 04:05 PM
  4. Code to get a Range RECTangle or PT
    By keepITcool in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-12-2005, 02:05 PM
  5. Rectangle that activates a macro
    By in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2005, 03:06 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