-
I'm trying to plot a single line on a graph using MSChart.
Instead of getting a single line, I get a series of lines which represent my data. Below is my code. txtX and txtY are textbox arrays that the user will use to input values for the line.
Private Sub cmdDraw_Click()
Dim arrData(2, 6)
Dim i, j, k As Integer
For i = 1 To 6
arrData(1, i) = txtX(i - 1).Text
arrData(2, i) = txtY(i - 1).Text
Next i
With LinGraph
.Repaint = False
.chartType = VtChChartType2dLine
.ColumnCount = 6
.RowCount = 6
.Data = arrData
.ColumnLabel = txtLinTrack.Text
.RowLabel = lblLinTag.Caption
.Repaint = True
End With
End Sub
-
Hi Laura,
I tried to get your code to run to find what is the problem, but I am getting a type mismatch error from the line
So much for that idea, then. But just from looking at your code - if you are just wanting to show one line, you don't need six rows. You SHOULD only need one. I am not sure that I understand what you are trying to do though, since you are using a multi-dimensional array.
Also, I have often been frustrated with MSChart, since it seems to have a mind of its own. Be sure that you set the RandomfILL property to false and maybe that will alleviate some of the problem (and help you avoid future headaches)!
[Edited by DrewDog_21 on 04-25-2000 at 06:51 PM]
-
I'm pretty sure that to assign an array of data to a MSChart control, you assign the array to the ChartData property of the control. The Data property is for assigning single data points.
[Edited by HarryW on 04-25-2000 at 11:24 PM]
-
Private Sub cmdDraw_Click()
OK so I tried changing the row to 1, the Column to 1, and both the column and the row to 1. These alkl produced a series of lines. The RandomFill property was already set to false, and I changed the .Data property to the .ChartData property (which was probably the reason for the mismatch error). Do you think it could be the structure of my array? The array I'm using for testing is (1,2,3,4,5,6;2,4,6,8,10,12). Do you know of any good references for MSChart? I've looked at the MSDN Library examples, but they are somewhat thin. I also have the EXPERT GUIDE TO VB6 which is not very helpful either.
Here is the updated code:
Dim arrData(2, 6)
Dim i, j, k As Integer
For i = 1 To 6
arrData(1, i) = txtX(i - 1).Text
arrData(2, i) = txtY(i - 1).Text
Next i
With LinGraph
.Repaint = False
.chartType = VtChChartType2dLine
.ColumnCount = 6
.RowCount = 1
For j = 1 To 6
.ChartData = arrData
Next j
.ColumnLabel = txtLinTrack.Text
.RowLabel = lblLinTag.Caption
.Repaint = True
End With
End Sub
-
I'm confused as to why you have
Code:
For j = 1 To 6
.ChartData = arrData
Next j
in there. That will just assign the same array 6 times. And yep, that's definitely why you got a type mismatch.
I have a pretty good reference book on VB controls, with about 30 pages on the MSChart control. If you want me to look something up just say (I'm not gonna type all 30 pages up though ;))
I'm not too sure why you have a 2-dimensional array but a Columncount of only 1. I've not used charts much yet (just about to start in fact) but I would have expected a Columncount of 2. Maybe, if there's values left over, the control is using them to make your extra lines?
By the way you can put your code in code tags to preserve formatting and add the VB colours. Just put the words 'code' and '/code' in square brackets [ & ] at either end of your block of code.
-
Microsoft's Visual Basic reference library (3 volume set) has about 200 pages of info on MSChart. It is kind of pricey but well worth it if you can get your hands on it.
-
How pricey is 'kind of'? The book I bought cost me about £15 I think.
If you're going to buy a boxed set like that, it might bt best to wait for VB7 now if it's coming out soon. I have no idea when it's coming out but there's been a lot of threads on it recently so I'd guess it's soon.
-
Ooops! Sorry about the for/next thing...not that it helped anything when I took it out. I'll look into some other references. Thanks for all your help.
-
Kind of pricey is around $150 - $200 in US Dollars depending on where you are. It has probably come down to around $100 now since VB6 has been out for awhile.