Thursday, January 14, 2010

Using Microsoft Chart Controls in the .NET 2.0 Framework


In .NET 3.5 SP1, Microsoft introduced the chart controls to the framework. This set of controls provide rich visualization of data in a different kinds of graphs and charts. The controls are databindable and highly customizable.

I happened to work at a project that required us to stick to the 2.0 version of the .NET framework due to production environment running on Windows 2000. Since I could see the graph controls would add business value to our application, I wanted to figure out if one could run the controls on a 2.0 framework - and you can. You might argue we live in the stone age (and you're right), but I'm sure we're not the only company left in the world in this situation. Therefore I here present you with a step-by-step guide on how to get your .NET Forms project running on a .NET 2.0-based client with chart controls. One catch: the development environment needs to have .NET 3.5 SP1 installed.

Step 1 through 3 are general installation instructions, 4 is the key to making it work on the 2.0 platform:

  1. Make sure you have .NET Framework 3.5 installed on your developer computer.

  2. Download and install Microsoft Chart Controls for .NET 3.5 from Microsoft.com on the developer computer.

  3. Open the Visual Studio project you want to work with and make sure you have the Chart control listed under the Data tab in the toolbox. If you don't: Select and right click the data tab and select Choose items, then scroll down and select the two Chart controls listed under .NET Framework Components.


  4. Add the following DLL as a reference to your project:

    C:\Program Files\Microsoft Chart Controls\Assemblies\System.Windows.Forms.DataVisualization.dll

    Open the properties of the reference and set Copy local to true
This will ensure that the Visualization-DLL is copied to the output folder when building or when building a MSI file from a setup project.

Happy charting!

10 comments:

  1. Hello,
    Tips does not works because System.Windows.Forms.DataVisualization.Charting use type from 3.5 like DateTimeOffSet

    ReplyDelete
  2. Actually I'm using this in a system in production today without problems. Have you tried it? If you're using Visual Studio 2010, maybe it is stricter on compile-time-checking. Just guessing here...

    ReplyDelete
  3. I did try it, was hoping it would work, but so far no luck. Chart simply does not appear on the test machine, which is a freshly installed XP Pro SP3 with only .NET 2.0 installed. I need this to work on Windows 2000 systems if possible!

    ReplyDelete
  4. Do you get an exception instead if you remove the .DLL's from the folder? Could it be that an exception is occuring in the creating of the graphs that is not renderd to the user? Try to get some more debug info on what's going on.

    ReplyDelete
  5. I realize this is an older thread, but I was wondering if you had used this control in a asp.net 2.0 site. Also did run into any issues deploying it to a production server running a 2.0 site?

    ReplyDelete
  6. I havent testes with ASP.NET 2.0 myself, so I cannot say for sure. I could only advice you to give it a try. You should be able to apply the same method to extract the System.Web.Ui.DataVisualization.Charting.dll as for the WinForms DLL.

    ReplyDelete
  7. It works. Although you can't directly drag and drop MS Chart from toolbox in .Net 2.0 project. But you can copy a MS Chart object from a WinForm in .Net 3.5Sp1 project, then paste it into a WinForm in .Net 2.0 project. Finally, you will get a MS Chart on WinForm just as it is dragged from toolbox.
    I had tested it to run on Windows 2000.
    Many thanks to Frode.

    ReplyDelete
  8. Getns any one can help, I am getting Error :An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.DataVisualization.dll while using VS2005 Chart Control to display data

    ReplyDelete