ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Plotting Graphs by Arrays (https://www.excelbanter.com/excel-programming/317565-plotting-graphs-arrays.html)

d.i.barr[_6_]

Plotting Graphs by Arrays
 

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 Whe=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.i.bar
-----------------------------------------------------------------------
d.i.barr's Profile: http://www.excelforum.com/member.php...fo&userid=1552
View this thread: http://www.excelforum.com/showthread.php?threadid=31937



All times are GMT +1. The time now is 02:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com