+ Reply to Thread
Results 1 to 3 of 3

data series doesn't show up on chart

Hybrid View

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    23

    data series doesn't show up on chart

    Hi,

    I have a macro that plots a bunch of graphs based on option box selections. All my graphing code is set up similar, but I'm having a problem with getting my macro to plot selected data and put in the series name.

    What happens is as follows:

    I two fuel types and two tests for each fuel type. I want to plot two graphs (one for each fuel type), each of which contains two series (for each of the tests conducted with that fuel type). The first graph does everything I want. But for the second graph, only one data series plots and the name of the series (labeled to the right) is "Series 1", not the name I referenced in my code. I think the problem has to do with my calls to "ActiveChart" but I as I'm new to VBA I don't know how to refer to a chart name when I try to add a new series to it.

    Below is my code:

    Formula: copy to clipboard
    If CheckBox3.Value = True Then

    Charts.Add

    With ActiveChart
    .Name = "Chart2"
    .ChartType = xlXYScatterSmooth
    'x axis label spacing
    .Axes(xlCategory).TickMarkSpacing = 10
    .Axes(xlCategory).TickLabelSpacing = 10
    .HasTitle = True
    .ChartTitle.Text = "T_SEV_IN - MT_SEV_BUR22 for 28% H2"
    'axes titles
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "T_SEV_IN (C)"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "D_TSEVIN_MTBUR22 (C)"
    .Location Where:=xlLocationAsObject, Name:="Plots"
    End With

    With ActiveChart.Parent
    .Height = 325
    .Width = 500
    .Top = Range("C29").Top
    .Left = Range("C5").Left
    End With

    Set SheetName3 = Worksheets("FB3")
    lastdatapoint3 = SheetName3.Cells(Rows.Count, 2).End(xlUp).Row

    With Charts("Chart2")
    .SetSourceData Source:=SheetName3.Range("$WB$3:$WB" & lastdatapoint3)
    .SeriesCollection(3).XValues = SheetName3.Range("$R$3:$R" & lastdatapoint3)
    .SeriesCollection(3).Name = Worksheets("Index").Range("A4")
    End With
    End If

    If CheckBox4.Value = True Then
    Set SheetName4 = Worksheets("FB4")
    lastdatapoint4 = SheetName4.Cells(Rows.Count, 2).End(xlUp).Row

    With Charts("Chart2")
    .SeriesCollection.NewSeries
    .SeriesCollection(4).Name = Worksheets("Index").Range("A5")
    .SeriesCollection(4).Values = SheetName4.Range("$WB$3:$WB" & lastdatapoint4)
    .SeriesCollection(4).XValues = SheetName4.Range("$R$3:$R" & lastdatapoint4)
    End With
    End If


    I know that my graph is in the if statement for the first checkbox. But, I always graph both of these checkboxes at the same time and I don't want the plot to show up unless the checkboxes are selected.

    All suggestions are appreciated!

  2. #2
    Registered User
    Join Date
    07-03-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: data series doesn't show up on chart

    for the second series i try to add, I also tried

    "With ActiveChart" instead of "With Charts("Chart2")" and that didn't work either

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: data series doesn't show up on chart

    fixed it.

    because it was a new chart, when i added a new series it was series 1,2,3,4....rather than the 12,13,14 I was trying to graph

    it works with activechart....but if anyone knows how to add a series to a chart by using it's name, please let me know

+ Reply to Thread

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