Adding MSChart to VB.NET

J

JJ

I am a novice at VB.NET and am trying to get the following code, downloaded
from MSDN to run.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arrData(2, 2)

arrData(1, 1) = "Jan" ' Set the labels in the first series.

arrData(2, 1) = "Feb"

arrData(3, 1) = "Mar"

arrData(1, 2) = 8

arrData(2, 2) = 4

arrData(3, 2) = 0.3

arrData(1, 3) = 0.2

arrData(2, 3) = 3

arrData(3, 3) = 6.3

MSChart1.ChartData = arrData 'MSChart1 has the blue squiggly line under
it.......this is MY PROBLEM

End Sub

I changed arrData to reflect zero based indexing.

I have added MSChart to the toolbox and used it on Form1, changing its
(name) property to Chart1.

I thought just adding a dim MSChart1 as Chart1 at the beginning of the sub
would work, it didn't.

What am I missing to get the compiler to recognize MSChart1 ?



Thanks for your time, J e r
 
A

Armin Zingler

JJ said:
I am a novice at VB.NET and am trying to get the following code,
downloaded from MSDN to run.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arrData(2, 2)

arrData(1, 1) = "Jan" ' Set the labels in the first series.

arrData(2, 1) = "Feb"

arrData(3, 1) = "Mar"

arrData(1, 2) = 8

arrData(2, 2) = 4

arrData(3, 2) = 0.3

arrData(1, 3) = 0.2

arrData(2, 3) = 3

arrData(3, 3) = 6.3

MSChart1.ChartData = arrData 'MSChart1 has the blue squiggly line
under it.......this is MY PROBLEM

End Sub

I changed arrData to reflect zero based indexing.

I have added MSChart to the toolbox and used it on Form1, changing
its (name) property to Chart1.

I thought just adding a dim MSChart1 as Chart1 at the beginning of
the sub would work, it didn't.

What am I missing to get the compiler to recognize MSChart1 ?

If it's name is Chart1, you must use

Chart1.ChartData = arrData
 
K

Ken Tucker [MVP]

Hi,

When I add a ms chart control to a form it default name is
AxMsChart1.

Ken
 
J

JJ

Ken Tucker said:
Hi,

When I add a ms chart control to a form it default name is
AxMsChart1.

Ken

Mine comes in as AxChartSpace1, but I changed it to Chart1 or MSChart1 while
trying to fix it. I've read where Visual Studio starting using the prefix
Ax....... to signify it was ActiveX but never attached much significance to
it because its just a name and we can name it anything we want, right?
Assuming it meets VB rules.

J e r
 
A

Armin Zingler

JJ said:
Changing it per your suggestion brings up the error, "'ChartData' is
not a member of 'AxOWC10.AxChartSpace'.

I do not have any imports statements, should I ?

It was you who wrote 'chartdata', so I didn't check if the property name was
also wrong.

I checked it now but the property is there. Are you sure you dropped a
*MSChart* control? If you use the MSChart, the namespace is
'AxMSChart20Lib', not 'AxOWC10'.
 
K

Ken Tucker [MVP]

Hi,

This should work if your mschart control is named chart1.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arrData(3, 3) As Object

arrData(1, 1) = "Jan" ' Set the labels in the first series.

arrData(2, 1) = "Feb"

arrData(3, 1) = "Mar"

arrData(1, 2) = 8

arrData(2, 2) = 4

arrData(3, 2) = 0.3

arrData(1, 3) = 0.2

arrData(2, 3) = 3

arrData(3, 3) = 6.3

Chart1.ChartData = arrData

End Sub



Ken
 
J

JJ

Ken Tucker said:
Hi,

This should work if your mschart control is named chart1.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arrData(3, 3) As Object
din arrData as type object also fails with message 'ChartData' is not a
member of 'AxOWC10.AxChartSpace'.

I changed the last line to:
'Chart1.ChartData = arrData 'so I could compile

Chart1.Visible() = True 'added code



and at least the form and chart display, the chart contains no data however.
 
J

JJ

Ken Tucker said:
Hi,

Are you sure you added ms chart control 6.0?

My tool bar said Microsoft Office Chart 10.0, so I added 6.0 as a separate
tool, changed my code to
'Chart1.ChartData = arrData

'Chart1.Visible() = True

AxMSChart1 = arrData 'the default name is now as you specified BUT
arrData now has the blue squiggly underline



the error message is Value of type '2-dimensional array of System.Object'
cannot be converted to 'AxMSChart20Lib.AxMSChart'.

I'm going to go back and play with the arrData dim statement.



P.S. I have Office XP installed. There is also Microsoft Office Chart 9.0
available. What determines which of the 3 Chart controls should be used ?



J e r
 
J

JJ

Ken Tucker said:
Hi,


Try this

AxMSChart1.ChartData = arrData

THAT'S IT!!!!!! Super Job, I would've never found it without you.
If you are ever in Saugerties, N.Y. look me up, I owe you the best meal in
town.


Thank you very much, J e r
 

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

Similar Threads


Top