Results 1 to 5 of 5

Thread: Clustered Bar Chart

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Clustered Bar Chart

    Hi,
    I am trying to create this chart with dates on x axis and clustered bar chart on y axis showing availability of equipment(Rented,Quoted,Available).

    I tried to write the following macro for the above requirement but i cant get x axis to show the dates and the bar chart on y axis does not show different colours for different status of equipment.

    The data is as follows

    A1:28882 C1:Status
    A2:09/09/2005 C2:Rented
    A3:09/16/2005 C3:Quoted

    The macro is as follows -----------------

    VB Code:
    1. Sub MakeRental()
    2.  
    3. Dim i As Integer
    4.  
    5. Worksheets("Rental").Select
    6. Worksheets("Rental").Range("A2:A3").Select
    7. 'Selection.DateFormat = "mm/dd/yyyy"
    8.            
    9.             Charts.Add
    10.         ActiveChart.Location Where:=xlLocationAsObject, Name:="Rental"
    11.             ActiveChart.ChartType = xlBarClustered
    12.  ActiveChart.SetSourceData Source:=Sheets("Rental").Range("R10"), PlotBy:=xlRows
    13.           ActiveChart.SetSourceData Source:=Sheets("Rental").Range("A1:A3"), PlotBy:=xlRows
    14.        
    15.     With ActiveChart
    16.         .HasLegend = True
    17.         .Legend.Select
    18.         Selection.Position = xlRight
    19.         .SeriesCollection(1).Name = "=""Rented"""
    20.         With ActiveChart.SeriesCollection.NewSeries
    21.             .Name = "Quoted"
    22.             .XValues = ActiveSheet.Range("A2:A3")
    23.         End With
    24.         With ActiveChart.SeriesCollection.NewSeries
    25.             .Name = "Available"
    26.         End With
    27.         .HasDataTable = False
    28.         .HasTitle = True
    29.         .ChartTitle.Characters.Text = "Rental Availability Chart"
    30.     End With
    31.  
    32.         ActiveChart.SeriesCollection(1).Select
    33.         With ActiveChart.ChartGroups(1)
    34.             .Overlap = 100
    35.             .GapWidth = 150
    36.             .HasSeriesLines = False
    37.         End With
    38.      
    39.      For i = 1 To 2
    40.             ActiveChart.SeriesCollection(1).Select
    41.             With Selection.Border
    42.                 .Weight = xlThin
    43.                 .LineStyle = xlAutomatic
    44.             End With
    45.             Selection.Shadow = False
    46.             Selection.InvertIfNegative = False
    47.             With Selection.Interior
    48.             If Worksheets("Rental").Cells(i+1 , 3) = "Rented" Then
    49.                 .ColorIndex = 4 'green
    50.             Else
    51.                 If Worksheets("Rental").Cells(i+1 , 3) = "Quoted" Then
    52.                     .ColorIndex = 3 'red
    53.                 End If
    54.             End If
    55.             .Pattern = xlSolid
    56.             End With
    57.             ActiveChart.ChartGroups(1).SeriesCollection(1).PlotOrder = 1
    58.     Next i
    59.  
    60.         With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory)
    61.            ' .MinimumScale = 9 / 9 / 2005
    62.             '.MaximumScale = 9 / 25 / 2005
    63.         End With
    64. End Sub

    ---------------------------------------------------

    Regards,
    Last edited by RobDog888; Sep 14th, 2005 at 11:34 AM. Reason: Added vbcode tags

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Clustered Bar Chart

    So what is the problem?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Clustered Bar Chart

    Welcome to the Forums.
    ...i cant get x axis to show the dates and the bar chart on y axis does not show different colours for different status of equipment.
    ..
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Clustered Bar Chart

    For each series; Rented,Quoted,Available - how are you determining the start and end dates?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Re: Clustered Bar Chart

    Let me explain the data in the fields

    The data is as follows

    A1:28882 C1:Status
    A2:09/09/2005 C2:Rented
    A3:09/16/2005 C3:Quoted

    This means that 28882,which is an equipment unit , has status Rented from date 9 Sep to 15 Sep and has status Quoted from 16 Sep onwards till end of month.

    The max and min values for x axis is given by the following code, which I came to know of this after posting the first thread in vbforums.com.

    The chart is meant for plotting status of equipment in different colours (on a bar on y axis)with respect to dates on x axis.

    I also would like to know how can i set .Majorunit in the following code.

    MinVal = #9/9/2005#
    MaxVal = #9/25/2005#
    With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
    .MinimumScale = MinVal
    .MaximumScale = MaxVal
    End With

    When i write the above code, the bar on the y axis does not appear anymore.I need to draw a bar on y axis which will show different colours for different status.

    Thanks and Regards

Posting Permissions

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



Click Here to Expand Forum to Full Width