Basic Getting Started Question/ Newbee
- I have installed the charts and am not able to get even a simple chart to appear. Not sure where I am supposed to paste the sample code. It is not clear since all the code are just snippets. I am running VS 2008 on a Windows 2008 VM. One is 64 bit, one is 32 bit. I paste in the below code into the Form_Load method and it either exits part way thru the exection on one VM or throws an error "A chart element with the name 'ByArray' could not be found in the 'SeriesCollection'." This is really frustrating. I have a codeplex project that I am trying to get some basic chart functionailty going and trying to decide between these controls, Telerik and dotnetcharting.com. Can anyone tell me why this 'basic' report won't render?
private
void Form1_Load(object sender, EventArgs e)
{
// initialize an array of doubles for Y values
double[] yval = { 5, 6, 4, 6, 3 };
// initialize an array of strings for X values
string[] xval = { "A", "B", "C", "D", "E" };
// bind the arrays to the X and Y values of data points in the "ByArray" series
chart1.Series[
"ByArray"].Points.DataBindXY(xval, yval);
// now iterate through the arrays to add points to the "ByPoint" series,
// setting X and Y values
for (int i = 0; i < 5; i++)
{
chart1.Series[
"ByPoint"].Points.AddXY(xval[i], yval[i]);
}
}
Mike
Answers
- Mike
I feel your pain, buddy :)
I started out a couple weeks ago. At first it was really confusing, like any new language would be when you don't know the Methods, Properties, etc.
But I came across this:
http://weblogs.asp.net/dwahlin/archive/2008/11/25/getting-started-with-the-asp-net-3-5-chart-control.aspx
and that at least helped me understand a little of how to display data in a chart. Once I got that I just started investigating.
I wasn't using a database so I skipped the first couple sections. I was just wanting to add the Integers from a List(Of Integer). Then the next section mentioned the chart has a ChartArea property - so I looked at that. You know, type Chart1.ChartAreas(0). in the code editor and look into all the stuff that comes up.
Then it mentions the Series property - so I looked into that. Type Chart1.Series...
Etc, etc. It wasn't long before I could display data from a datatable in a chart, display 2 sets of data in a StackedBar chart, etc.
So let me try to help with your problem - although some of it may be wrong. One thing I noticed is when you add a chartcontrol to your Form, you start with a default Series. This Series has an index of 0. Try changing the ByArray in your Chart1.Series("ByArray") to a zero. Or rename your Series to ByArray.
by running the below in the Form_Load event, but you could also do it in a Button_Click event, you should get a basic chart (I think I interpreted the code correctly - I use VB.NET, not C).
I hope this helps a little
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim xval As String() = New String() {"A", "B", "C", "D", "E"} Dim yval As Double() = {5, 6, 4, 6, 3} 'to add data using a collection 'Chart1.Series(0).Name = "ByArray" 'Chart1.Series("ByArray").Points.DataBindXY(xval, yval) 'to add data points one by one For i As Integer = 0 To 4 Chart1.Series(0).Points.AddXY(xval(i), yval(i)) Next End Sub
Alex, from this Forum, also has a Weblog with a lot of chart control stuff
http://blogs.msdn.com/alexgor/archive/tags/Chart/default.aspx- Marked As Answer byMike Wilmot Tuesday, November 10, 2009 4:02 PM
All Replies
- It is probably just user error, but here is my take after a day of trying to figure this stuff out...
-the setup and 'orientation' phase of trying these for the 1st time is challenging. There are separate areas for the install vs. the help files vs. the samples and finding how to register the controls, find them in the toolbar, etc... is not intuitive. The samples aren't as much samples as they are code snippets that don't necessaryily compile for a generic chart with "Chart1" or "chart1" as some of the samples have and others have "Chart1" and the sample output definitely doesn't match the output you get when you run the actual samples. Debugging the samples for a newbee is tough when 'Series' etc are missing. Didn't get any immediate feedback from a posting I left. It is probably just the fact that I have been out of dev for awhile, but I wish it were easier to do awesome stuff very quickly.
Mike - hehe, I like this line "I wish it were easier to do awesome stuff very quickly" ... don't we all.
So, as someone who hadn't been doing .NET very long this time around when I came to doing ASP.NET and charts, I felt the samples were rather well laid out and that I was able to replicate the process fairly smoothly. In less than a month I've gotten to where I feel quite comfortable with them, and except for a few rough edges, they're quite nice, if you want a simple graph (which I do).
So, having said that, I'ld like to just offer some encouragement for a moment. I remember setting up the project for the first time, and the installs, but as for "don't necessarily compile" I disagree. Are you using VS2k8?
As for "why this basic report won't render" can you offer any more of the code? that bit above is sorely lacking, so it's hard for anyone to help you. But I know the frustration, so I'm not going to be the one to hold it against you.
I'll likely be back on tonight, I'll see if you've left anything then. Otherwise, perhaps tomorrow?
Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now. - Mike
I feel your pain, buddy :)
I started out a couple weeks ago. At first it was really confusing, like any new language would be when you don't know the Methods, Properties, etc.
But I came across this:
http://weblogs.asp.net/dwahlin/archive/2008/11/25/getting-started-with-the-asp-net-3-5-chart-control.aspx
and that at least helped me understand a little of how to display data in a chart. Once I got that I just started investigating.
I wasn't using a database so I skipped the first couple sections. I was just wanting to add the Integers from a List(Of Integer). Then the next section mentioned the chart has a ChartArea property - so I looked at that. You know, type Chart1.ChartAreas(0). in the code editor and look into all the stuff that comes up.
Then it mentions the Series property - so I looked into that. Type Chart1.Series...
Etc, etc. It wasn't long before I could display data from a datatable in a chart, display 2 sets of data in a StackedBar chart, etc.
So let me try to help with your problem - although some of it may be wrong. One thing I noticed is when you add a chartcontrol to your Form, you start with a default Series. This Series has an index of 0. Try changing the ByArray in your Chart1.Series("ByArray") to a zero. Or rename your Series to ByArray.
by running the below in the Form_Load event, but you could also do it in a Button_Click event, you should get a basic chart (I think I interpreted the code correctly - I use VB.NET, not C).
I hope this helps a little
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim xval As String() = New String() {"A", "B", "C", "D", "E"} Dim yval As Double() = {5, 6, 4, 6, 3} 'to add data using a collection 'Chart1.Series(0).Name = "ByArray" 'Chart1.Series("ByArray").Points.DataBindXY(xval, yval) 'to add data points one by one For i As Integer = 0 To 4 Chart1.Series(0).Points.AddXY(xval(i), yval(i)) Next End Sub
Alex, from this Forum, also has a Weblog with a lot of chart control stuff
http://blogs.msdn.com/alexgor/archive/tags/Chart/default.aspx- Marked As Answer byMike Wilmot Tuesday, November 10, 2009 4:02 PM
Mike
I feel your pain, buddy :)
I started out a couple weeks ago. At first it was really confusing, like any new language would be when you don't know the Methods, Properties, etc.
But I came across this:
http://weblogs.asp.net/dwahlin/archive/2008/11/25/getting-started-with-the-asp-net-3-5-chart-control.aspx
and that at least helped me understand a little of how to display data in a chart. Once I got that I just started investigating.
I wasn't using a database so I skipped the first couple sections. I was just wanting to add the Integers from a List(Of Integer). Then the next section mentioned the chart has a ChartArea property - so I looked at that. You know, type Chart1.ChartAreas(0). in the code editor and look into all the stuff that comes up.
Then it mentions the Series property - so I looked into that. Type Chart1.Series...
Etc, etc. It wasn't long before I could display data from a datatable in a chart, display 2 sets of data in a StackedBar chart, etc.
So let me try to help with your problem - although some of it may be wrong. One thing I noticed is when you add a chartcontrol to your Form, you start with a default Series. This Series has an index of 0. Try changing the ByArray in your Chart1.Series("ByArray") to a zero. Or rename your Series to ByArray.
by running the below in the Form_Load event, but you could also do it in a Button_Click event, you should get a basic chart (I think I interpreted the code correctly - I use VB.NET, not C).
I hope this helps a little
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load Dim xval As String () = New String () {"A" , "B" , "C" , "D" , "E" } Dim yval As Double () = {5, 6, 4, 6, 3} 'to add data using a collection 'Chart1.Series(0).Name = "ByArray" 'Chart1.Series("ByArray").Points.DataBindXY(xval, yval) 'to add data points one by one For i As Integer = 0 To 4 Chart1.Series(0).Points.AddXY(xval(i), yval(i)) Next End Sub
Alex, from this Forum, also has a Weblog with a lot of chart control stuff
http://blogs.msdn.com/alexgor/archive/tags/Chart/default.aspx
Except your code is in VB and his is C# and he's already having issues. Plus, we don't have his front end code; this is an incomplete example. It's not sane for us to suggest changes to his code without knowing how he has things structured.
Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now.It looks like you've found the "Basic Data Population" -example in the Samples Environment. The source-tab in each example is only supposed to hilight a sample specific piece of code. The full code for each example (except the gallery charts, which are just images) can easily be browsed in the solution explorer.
The "Creating a Chart Dynamically" -example (underneath basic data population) is imho a better example and is just about the only example where the source-tab has a full, runnable piece of code. (also, it looks just like my example in this thread.)
It is true though, that in some of the samples the source tabs have old / buggy code. For example calls to functions that don't exist with that name, capitalization errors, mixed C# and VB -code..- Ok, now I feel really goofy for not having realized what sipla did. Sipla, I believe you've hit the nail on the head...
Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now.


