Plotting Graphs by Arrays

D

d.i.barr

Hi there,
I have a problem here that mey be quite easy to sort out as I think i
is merely a syntax problem - or someone may be able to suggest a wa
around using arrays full stop. I want to plot scatter graphs for som
data I have availiable, but it is of varying length (typically betwee
6 and 24 samples). I have two proceedures, the first gathers the dat
and assigns this to arrays, and the second one plots them. Now, bot
worked independantly (the graph plotter was using a range rather tha
an array) but when I tried passing the arrays to the second sub, i
wouldn't work.

Option Explicit

Sub AssignValues()
Dim i As Integer
Dim valueX() As Single
Dim valueY() As Single

'Obtain all the transmission times in milli-seconds (or the
axis).
i = 0
Worksheets(1).Range("B1").Offset(6, 1).Activate
Do
ActiveCell.Offset(0, 1).Activate
ReDim Preserve valueY(i)
valueY(i) = ActiveCell.Value
i = i + 1
Loop While ActiveCell.Offset(0, 1).Value <> ""

'Obtain all the lung volumes in litres (or the X axis).
i = 0
Range("B1").Offset(5, 1).Activate
Do
ActiveCell.Offset(0, 1).Activate
ReDim Preserve valueX(i)
valueX(i) = ActiveCell.Value
i = i + 1
Loop While ActiveCell.Offset(0, 1).Value <> ""
Call PlotGraph(valueX(), valueY())
End Sub

Sub PlotGraph(valueX() As Single, valueY() As Single)
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A25")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = valueX
ActiveChart.SeriesCollection(1).Values = valueY
ActiveChart.SeriesCollection(1).name = "=""AM Channel 1"""
ActiveChart.Location Where:=xlLocationAsObject, name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "AM Title"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "
lable"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "
lable"
End With
ActiveChart.HasLegend = False
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 15
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 15
.Weight = xlHairline
.LineStyle = xlContinuous
End With
End Sub

Now any comments would be appreciated. As you can tell the second su
was recorded rather than written, so any comments on how to smarten i
up would be appreciated.

I am going to anticipate a question that some of you may be thinking
whay plot from arrays? Well, I would rather not, and just plot fro
ranges but I don't know how (I'm aware that plotting from arrays has
limit on the characters you can use). An ideal answer to this proble
I suppose would be a way to plot variable lengths of rows into chart
(continued up until the next cell is empty). This is what I originall
tried to do but failed.

Thanks in advance,
Dave..
 
D

d.i.barr

Unless you can make a suggeestion as to how to read across variabl
lengths of ranges, the relevant section is:
ActiveChart.SeriesCollection(1).XValues = valueX
ActiveChart.SeriesCollection(1).Values = valueY

Value X and Y are both arrays, how would I write this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top