Adding a chart to a Web page is surprisingly tricky. There are several ways to add a chart to an ASP.NET Web page. You can buy and use a commercial package such as the one from Telerik. You can use an open source client side JavaScript library such as Flot (which also works with non-ASP.NET pages).

For ASP.NET Web Form pages (aka .aspx pages) you can use the server side Chart control from the System-Web-UI-DataVisualization-Charting namespace. For ASP.NET Razor pages (aka MVC or plain Razor pages) you can use the server side Chart control from the System-Web-Helpers namespace.

There are many pros and cons to each approach. I found that the documentation for adding a chart to an ASP.NET Web Form page was horrible. Here’s a quick walk-through to add a chart to an ASP.NET Web Form, describing some of the problems I ran into and what I did to fix them.

Now specify HTTP and http: //localhost /ASPWebFormChart for the location. This will create an almost empty Web site, giving you just Web.config and Web.Debug.config files. Note that this creates a root directory named ASPWebFormChart at C:\inetpub\wwwroot.

In the Solution Explorer window, right-click on the bolded Web site name and click Add | Add New Item | Visual C# | Web Form and name it ChartDemo.aspx and optionally uncheck the ‘Place code in separate file’ if you want to keep things simple with all your code in one place.

At this point the Web page has this (I’ve replaced all less-than and greater-than characters with ‘{‘ and ‘}’ so my blog software doesn’t blow up):

I found this required config setting information after a lengthy and painful search on the Internet. I don’t know why the XML wasn’t added by VS as it should have.

I was still getting errors trying to run the Web page. Next, I had to edit the security permissions on the top level ASPWebFormChart directory. I gave Write permissions to the NETWORK SERVICE account and the IIS_USRS account. I think what was happening is that the Chart control writes an image of the chart, or data that can be used to generate an image, on the Server, so Write permissions are needed.

Anyway, I got an empty chart to display. Next, I edited the ASP code by adding some dummy hard-coded data points so I could see something:

The Chart control has a huge number of customization points (colors, titles, and so on), and can use data from a text file or a SQL database. These are non-trivial tasks.

From a larger perspective, this example points out a huge problem with Web development. Things are just too complicated, and documentation is often non-existent or out of date or just incorrect. This chaos isn’t helped by the constant creation of new frameworks for Web applications. I love Microsoft technologies, but ASP.NET has a long, long, long way to go to become what I’d consider a truly mature professional technology