Hello.
I've made a procedure that performs calculations on a beam.
I've divided the beam into x datapoints (each of which describes the forces in action at that particular point).
The users aren't interested in seeing these data but only the resulting graphs.
So basically i want to make charts from these datapoints (which i've stored internally in the procedure in different arrays) without having to plot the datapoints in the worksheet.
Can anyone help please??
This array can be assigned directly to a chart series.
e.g.Sub AssignArray() Dim Points, Forces Points = Array(5, 15, 8) Forces = Array(1, 3, 9) ActiveChart.SeriesCollection(1).XValues = Points ActiveChart.SeriesCollection(1).Values = Forces End Sub
Last edited by rwgrietveld; 11-26-2009 at 06:46 AM.
Looking for great solutions but hate waiting?
Seach this Forum through Google
www.Google.com (e.g. +multiple +IF site:excelforum.com/excel-general/ )
www.Google.com (e.g. +fill +combobox site:excelforum.com/excel-programming/ )
Ave,
Ricardo
I'm not quite there yet unfortunately:
I've made an array containing the numbers of all the datapoints (in this case 1-100) which i want plottet on the x-axis and i want to plot some corresponding values from my beamcalculation on the y-axis.
Here is some of the code i've written:
Dim xArray(ANTALDATAPUNKTER) As Byte (the number of datapoints)
Dim ufinTotalArray(ANTALDATAPUNKTER) As Single (an array containing the corresponding values to each x)
.
.
. (a lot of calculations filling the ufinTotalarray with data and the xArray with the numbers 1-100 in this case)
.
.
.
And now i want to make the graf using the data from the arrays:
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SeriesCollection(1).XValues = xArray
ActiveChart.SeriesCollection(1).Values = ufinTotalArray
ActiveChart.SeriesCollection(1).Name = "Deformation"
But this doesn't work.
Can you tell what's wrong??
And while i'm at it, i've noticed that when charting using Excel (and not vba) each graf is given a shapename (like "shape xx") and when i copy the sheet this shapenumber changes. How can name the graph/shape manually?
Last edited by Kim1974; 11-26-2009 at 12:40 PM.
Almost there. need to add NewSeries ! and I belive you need a different chart typeSub datap() Const ANTALDATAPUNKTER = 100 Dim xArray(1 To ANTALDATAPUNKTER) As Single 'Byte 'the number of datapoints Dim ufinTotalArray(1 To ANTALDATAPUNKTER) As Single 'an array containing the corresponding values to each x Dim x As Long For x = 1 To 100 xArray(x) = x ufinTotalArray(x) = (x ^ 2) / 8 + 2 * x - 5 Next x Charts.Add ActiveChart.ChartType = xlXYScatterSmooth ActiveChart.SeriesCollection.NewSeries ActiveChart.SeriesCollection(1).XValues = xArray ActiveChart.SeriesCollection(1).Values = ufinTotalArray ActiveChart.SeriesCollection(1).Name = "Deformation" End Sub
Looking for great solutions but hate waiting?
Seach this Forum through Google
www.Google.com (e.g. +multiple +IF site:excelforum.com/excel-general/ )
www.Google.com (e.g. +fill +combobox site:excelforum.com/excel-programming/ )
Ave,
Ricardo
Hi Kim
please put your code between code tags like this: [code] your code [/code]. That will make the code easier to read and copy. HTML otherwise strips out indentation and consecutive spaces.
hello rwgrietveld
I've tryed to run your procedure but i get a runtime error 1004 in this line:
The error (translated from danish) reads something like this: "Can't define property XValues for the class Series"ActiveChart.SeriesCollection(1).XValues = xArray
Each series formula has a maximum length of 1024 characters.
So for a series with labels of a,b,c,d and data of 1,2,3,4 the series formula would look like this
=SERIES(,{"a","b","c","d"},{1,2,3,4},1)
If you divide the values by 3 then the formula balloons.
=SERIES(,{"a","b","c","d"},{0.333333333333333,0.666666666666667,1,1.33333333333333},1)
So if you have +100 decimal data values you have problably exceeded the limit.
Jon Peliter has some code for delinking charts from ranges to array values.
http://peltiertech.com/Excel/ChartsH...ChartData.html
In the code is examples of dealing with this issue.
Good addition Andy,
Didn't know about the limit.
Kim You could try to limit the number of points OR
limit the accuracy. In a graph, this is most probably not significant.
Looking for great solutions but hate waiting?
Seach this Forum through Google
www.Google.com (e.g. +multiple +IF site:excelforum.com/excel-general/ )
www.Google.com (e.g. +fill +combobox site:excelforum.com/excel-programming/ )
Ave,
Ricardo
Thank you for the reply both of you (rwgrietveld and Andy Pope).
rwgrietveld: you're right.
Each corresponding calculation doesn't need to be that accurate since it is for chart-use only so i think i'll declare x as byte (since i never need more than 256 datapoints) and the result as integer (thus avoiding decimals).
Last edited by Kim1974; 11-27-2009 at 06:44 AM.
I just made a simple test:
In this example (with 82 datapoints) i get the same runtime error whereas if i choose 81 datapoints (or less) it works fine.Sub datap() Const ANTALDATAPUNKTER = 82 Dim xArray(1 To ANTALDATAPUNKTER) As Byte Dim ufinTotalArray(1 To ANTALDATAPUNKTER) As Integer Dim x As Byte For x = 1 To ANTALDATAPUNKTER xArray(x) = x ufinTotalArray(x) = x Next x Charts.Add ActiveChart.ChartType = xlXYScatterSmooth ActiveChart.SeriesCollection.NewSeries ActiveChart.SeriesCollection(1).XValues = xArray ActiveChart.SeriesCollection(1).Values = ufinTotalArray ActiveChart.SeriesCollection(1).Name = "Deformation" ActiveChart.Location Where:=xlLocationAsObject, Name:="Ark1" End Sub
Since the value = the datapoint (ufinTotalArray(x) = x) it seems to me, that
the SeriesCollection(1).Values only contains 82*(1+1) = 164 caracters (much less than 1024) and still it crashes??
Frustrating is it. You have reached a limit in what the chart will allow with code and arrays.
If you had a chart with a series that reference the values 1 to 81 in the range A1:A81 you could use this code to convert range to array.
Increase that to row 82 and the above will fail.activechart.SeriesCollection(1).values=activechart.SeriesCollection(1).values
Why do you not want to use a worksheet to hold the values?
Hello Andy.Why do you not want to use a worksheet to hold the values?
The reason i don't want the worksheet to hold the values is this:
I'm making a worksheet that calculates different forces and deflections at x number of places in a beam (i "slice" the beam into x slices).
Each sheet holds the information for one beam and i want each of these sheets to be cleansed of any unnecessary information. I only want the graphs depicting these forces and deflections and then some textoutput with maximum values.
And then i want to be able to make multiple copies of the sheet so i can have multiple different beams (different after i change the input to the procedure that is) in one workbook.
If i have one sheet for the beam and one sheet to hold the data for the beam there is to big a risc of confusion at some point
EDIT: i forgot to mention, that i want to be able to manually delete some rows in the beam-sheet. If i put the data in that sheet and hides them by setting the colomnwith to 0, these data will be deleted
Last edited by Kim1974; 11-27-2009 at 11:13 AM.
If the chart is on a chart sheet then I can how a chart sheet AND data sheet may make things difficult to keep together.
But you code moves the chart to a worksheet, which would suggest the chart and data could reside on the same worksheet.
I'm still not getting why you can not use a hidden range to hold the chart information.
Maybe you're right that i should just transfer the data from the arrays to the same worksheet as the beam-sheet and then make sure to refresh the data if i delete some of the rowsI'm still not getting why you can not use a hidden range to hold the chart information.
Anyhow, thank you for taking the time to help me out.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks