I'm building a chart dynamically with 6 series on a stacked line chart (xlLineMarkersStacked).
For some reason, only the top series is displaying on the plot area. All series have data behind them and are represented on the legend.
If I right click on the plot area, and select "Select Series". Then use the "up arrow" move a lower series to the top of the order, it then displays and the previous series that was on top disappears along with the rest of the series that are not at the top.
Any ideas why?
For some reason, only the top series is displaying on the plot area. All series have data behind them and are represented on the legend.
If I right click on the plot area, and select "Select Series". Then use the "up arrow" move a lower series to the top of the order, it then displays and the previous series that was on top disappears along with the rest of the series that are not at the top.
Any ideas why?
Code:
Function BuildProcessChart(ByVal bShowSurfaceWind) As Boolean
Dim nLastProcessRow As Integer, nSeriesIdx As Integer, idx As Integer
Dim dMaxVal As Double
Dim sRange As String
Dim chObj As ChartObject
ActiveWorkbook.Worksheets(PROCESSWIN_TAB).Activate
'Remove existing charts on this worksheet
On Error Resume Next
For Each chObj In ActiveSheet.ChartObjects
chObj.Delete
Next chObj
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GET MAXIMUM VALUE from process data worksheet
nLastProcessRow = xlLastRow(PROCESSDATA_TAB)
If nLastProcessRow < 2 Then
BuildProcessChart = False
MsgBox "No Data found to process", vbCritical, "No Data"
Exit Function
Else
BuildProcessChart = True
End If
sRange = "E2:I" & nLastProcessRow
Set rRange = ActiveWorkbook.Worksheets(PROCESSDATA_TAB).Range(sRange)
With ActiveWorkbook
dMaxVal = Application.Max(rRange)
End With
nMaxScaleVal = Application.RoundUp(dMaxVal, 0) + 500
'Go to the Process Chart worksheet
ActiveWorkbook.Worksheets(PROCESSWIN_TAB).Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkersStacked
'get the chart name for use in other routines
pos1 = InStr(1, ActiveChart.Name, "Chart")
lenChartName = Len(ActiveChart.Name) - pos1 + 1
gPWChartName = Right(ActiveChart.Name, lenChartName)
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 0
.MaximumScale = Round(dMaxVal) + 100
.MinorUnitIsAuto = True
.MajorUnit = gProcChartYMajorUnits
.HasMajorGridlines = True
.MajorGridlines.Border.Color = RGB(200, 200, 200)
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
sSeriesStringStart = "='Process Data'!"
sSeriesRowStart = "$2"
sSeriesRowEnd = "$" & nLastProcessRow
idx = 1
sSeriesColumn = "$I"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Break Surface Wind"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 3
.Weight = 2
.LineStyle = xlContinuous
End With
With Selection
.Smooth = True
.MarkerStyle = xlMarkerStyleNone
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
idx = idx + 1
sSeriesColumn = "$H"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Test 1"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 6
.Weight = 2
.LineStyle = xlContinuous
End With
With Selection
.Smooth = True
.MarkerStyle = xlMarkerStyleNone
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
idx = idx + 1
sSeriesColumn = "$G"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Test 2"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 3
.Weight = 2
.LineStyle = xlContinuous
End With
With Selection
.Smooth = True
.MarkerStyle = xlMarkerStyleNone
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
idx = idx + 1
sSeriesColumn = "$F"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Test 3"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 3
.Weight = 2
.LineStyle = xlDash
End With
With Selection
.Smooth = True
.MarkerStyle = xlMarkerStyleNone
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
idx = idx + 1
sSeriesColumn = "$E"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Test 4"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 3
.Weight = 2
.LineStyle = xlDot
End With
With Selection
.Smooth = True
.MarkerStyle = xlMarkerStyleNone
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
idx = idx + 1
sSeriesColumn = "$J"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(idx).Name = "=""Test 5"""
ActiveChart.SeriesCollection(idx).Values = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
ActiveChart.SeriesCollection(idx).Select
With Selection.Border
.ColorIndex = 2
.Weight = 0
.LineStyle = xlLineStyleNone
End With
With Selection
.Smooth = True
.MarkerSize = 6
.MarkerForegroundColorIndex = 11
.MarkerBackgroundColorIndex = 11
.MarkerStyle = xlMarkerStyleCircle
End With
sSeriesColumn = "$A"
ActiveChart.SeriesCollection(idx).XValues = sSeriesStringStart & sSeriesColumn & sSeriesRowStart & ":" & sSeriesColumn & sSeriesRowEnd
With ActiveChart
.Legend.Border.LineStyle = xlContinuous
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = ActiveWorkbook.Sheets(GRAPH_TAB).cboXAxis.Value
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = ActiveWorkbook.Sheets(GRAPH_TAB).cboYAxis.Value
End With
'add title to Y Axis
With ActiveChart
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
gProcessChartYAxisTitle
End With
With ActiveChart.Parent
.Top = 170
.Left = 100
.Height = 335
.Width = 714
End With
End Function 'BuildProcessChart