Hello Forum,
I am writing VBA code to make a scatterplot of data contained in two
arrays dim As Double. Along with the points that are plotted
I would like to have a line plotted from coordinates (0,0) to (1,1).
The only way that I know of to create this line is to use TrendLine
and specify as xlLinear. So far i have the plots of the points and
the trendline but I would like to have the trendline as green
instead of the default black. I cannot find the parameter to
change to make this happen. I have looked everywhere that I know
to look and can't find anything. My last hope was to record a
macro of creating the chart I want but none of the line
formatting commands were recorded for some reason. So I am stumped.
Also, I would like to specify major and minor gridlines on the
plot and any help with that would be appreciated.
My apologize for the inefficient code. This is my first VBA
project.
I would supply a graphic of the plot I have now and one of
how I would like it to be but I cannot upload any images.
Thanks for the help
Jim
********************************************
scalednumfail and scaledw Dim As Double and passed to subroutine
Sub UnitTTTplotsub(scalednumfail, scaledw)
Dim UnitTTTChtObj As ChartObject
Dim UnitTTTSeries As Series
Set UnitTTTChtObj = ActiveSheet.ChartObjects.Add _
(Left:=586, Width:=400, Top:=560, Height:=300)
UnitTTTChtObj.Chart.ChartType = xlXYScatter
'Delete other series so only the desired data will plot
'With UnitTTTChtObj
'Do Until Chart.SeriesCollection.Count = 0
'Chart.SeriesCollection(1).Delete
'Loop
'End With
Set UnitTTTSeries = UnitTTTChtObj.Chart.SeriesCollection.NewSeries
With UnitTTTSeries
.XValues = scaledw
.Values = scalednumfail
.Name = UnitTTTplot
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 3
End With
With UnitTTTChtObj.Chart
.HasTitle = True
.ChartTitle.Text = "Unit TTT Plot"
.HasLegend = False
With UnitTTTChtObj.Chart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "Scaled wi"
End With
With UnitTTTChtObj.Chart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "Scaled Failure i/(n-1)"
End With
'Add additional series for unit square slope equal 1 for comparing appropriateness of model
Set UnitTTTSeries = UnitTTTChtObj.Chart.SeriesCollection.NewSeries
With UnitTTTSeries
.Trendlines.Add Type:=xlLinear
.XValues = Array(0, 1)
.Values = Array(0, 1)
.Name = UnitTTTplot
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 3
End With
End With
End Sub
**********************
I am writing VBA code to make a scatterplot of data contained in two
arrays dim As Double. Along with the points that are plotted
I would like to have a line plotted from coordinates (0,0) to (1,1).
The only way that I know of to create this line is to use TrendLine
and specify as xlLinear. So far i have the plots of the points and
the trendline but I would like to have the trendline as green
instead of the default black. I cannot find the parameter to
change to make this happen. I have looked everywhere that I know
to look and can't find anything. My last hope was to record a
macro of creating the chart I want but none of the line
formatting commands were recorded for some reason. So I am stumped.
Also, I would like to specify major and minor gridlines on the
plot and any help with that would be appreciated.
My apologize for the inefficient code. This is my first VBA
project.
I would supply a graphic of the plot I have now and one of
how I would like it to be but I cannot upload any images.
Thanks for the help
Jim
********************************************
scalednumfail and scaledw Dim As Double and passed to subroutine
Sub UnitTTTplotsub(scalednumfail, scaledw)
Dim UnitTTTChtObj As ChartObject
Dim UnitTTTSeries As Series
Set UnitTTTChtObj = ActiveSheet.ChartObjects.Add _
(Left:=586, Width:=400, Top:=560, Height:=300)
UnitTTTChtObj.Chart.ChartType = xlXYScatter
'Delete other series so only the desired data will plot
'With UnitTTTChtObj
'Do Until Chart.SeriesCollection.Count = 0
'Chart.SeriesCollection(1).Delete
'Loop
'End With
Set UnitTTTSeries = UnitTTTChtObj.Chart.SeriesCollection.NewSeries
With UnitTTTSeries
.XValues = scaledw
.Values = scalednumfail
.Name = UnitTTTplot
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 3
End With
With UnitTTTChtObj.Chart
.HasTitle = True
.ChartTitle.Text = "Unit TTT Plot"
.HasLegend = False
With UnitTTTChtObj.Chart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "Scaled wi"
End With
With UnitTTTChtObj.Chart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "Scaled Failure i/(n-1)"
End With
'Add additional series for unit square slope equal 1 for comparing appropriateness of model
Set UnitTTTSeries = UnitTTTChtObj.Chart.SeriesCollection.NewSeries
With UnitTTTSeries
.Trendlines.Add Type:=xlLinear
.XValues = Array(0, 1)
.Values = Array(0, 1)
.Name = UnitTTTplot
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 3
End With
End With
End Sub
**********************