asp.net c# sample code errors

I am following a video to create a sample chart; link: http://www.asp.net/web-pages/videos/aspnet-razor-pages/displaying-data-in-a-chart-(part-1)

I am getting a 2 errors (I solved error 1) most likely because the author is using MVC, layout etc but I am creating it in vs2010 4.0 asp.net c#.

Question: Could you please take a look at this code and show me how I can handle these errors?

Thank you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;

public partial class z_CrimeRate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var chartImage = new Chart(600, 400);  //1: Error 57 'System.Web.UI.DataVisualization.Charting.Chart' does not contain a constructor that takes 2 arguments	

        chartImage.AddTitle("Sample Chart");   //2: Error 59 'System.Web.UI.DataVisualization.Charting.Chart' does not contain a definition for 'AddSeries' and no extension method 'AddSeries' accepting a first 
                                               //argument of type 'System.Web.UI.DataVisualization.Charting.Chart' could be found (are you missing a using directive or an assembly reference?)	
        chartImage.AddSeries(
                Name: "Decade",
                axisLabel: "Incidence",
                xValue: new[] {"1970","1980","1990","2000","2010"},
                yValues: new[] {"9","22","52","89","123"});
  
    chartImage.write();            //3: Error 54 Invalid token '(' in class, struct, or interface member declaration	



    }
}

Open in new window

Error 1 was resolved doing:
var chartImage = new Chart();        
        chartImage.Width = 600;
        chartImage.Height = 400;
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Not sure what that sample code is doing, seems to be for a different class altogether (didn't watch the video)...

Here's a simple example for a number of 'standard' ASP.NET chart properties, if you want it dynamically generated:
        protected void Page_Load(object sender, EventArgs e) {

            var chartImage = new Chart();
            chartImage.Width = 600;
            chartImage.Height = 400;

            chartImage.Titles.Add("Sample Chart");
            chartImage.Series.Add("Decade");
            chartImage.Legends.Add(chartImage.Series[0].Name); // optional, show legend

            // add data points
            object[] xValue = { "1970", "1980", "1990", "2000", "2010" };
            object[] yValues = { "9", "22", "52", "89", "123" };
            for (int x = 0; x < xValue.Length; x++) {
                chartImage.Series[0].Points.AddXY(xValue[x], yValues[x]); // may need to cast to double, if "option strict"
            }

            chartImage.ChartAreas.Add("chartArea0"); // always need to add this
            chartImage.ChartAreas[0].AxisX.Title = "Decade"; // optional, show axis x title
            chartImage.ChartAreas[0].AxisY.Title = "Incidence"; // optional, show axis y title

            chartImage.ImageStorageMode = ImageStorageMode.UseImageLocation; // avoid having to define http handler for now, simpler for quick testing
            this.Controls.Add(chartImage); // add to page for automatic rendering
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you very much. I have some followup questions on this chart. I will post the links here for the new question if you have some time to post a comment for it.

Regards,

Mike
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
0
Robert SchuttSoftware EngineerCommented:
Sure, if it's still unanswered, I'll have a go in a little bit.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.