Getting Started with Microsoft Chart Controls for Microsoft .NET Framework 3.5Microsoft Chart Controls for Microsoft .NET Framework 3.5 provide a powerful, flexible, and easy-to-use charting library for Windows Forms and ASP.NET applications. Introduced as a free add-on for .NET 3.5, these controls let developers create a wide variety of charts — from simple line and bar charts to advanced financial, statistical, and 3D visualizations — without needing third-party components.
This article walks through the essentials: installation, basic concepts, creating charts in both Windows Forms and ASP.NET, common customization techniques, data binding, performance tips, and troubleshooting.
What are Microsoft Chart Controls?
Microsoft Chart Controls are a set of managed controls built on top of GDI+ that integrate into Visual Studio and the .NET Framework. They support dozens of chart types (e.g., Column, Line, Pie, Area, Candlestick, Stock, Bubble, Radar), multiple series and axes, legends, labels, annotations, and interactive features such as tooltips and zooming.
Key benefits:
- Easy integration with Visual Studio designers
- Rich customization (styles, colors, markers, gradients, 3D)
- Data binding support for many data sources
- Export to image formats (PNG, JPEG, GIF, BMP)
- Programmatic control over rendering and interactivity
Installation and setup
- Download and install the Microsoft Chart Controls package for Microsoft .NET Framework 3.5 if not already installed. (On older systems this was distributed as an add-on; on updated developer machines it may already be present.)
- For ASP.NET, install and register the Chart Controls ASP.NET add-on (System.Web.DataVisualization).
- Add references in your project:
- System.Windows.Forms.DataVisualization (for Windows Forms)
- System.Web.DataVisualization (for ASP.NET) In some installs, the assembly is named System.Windows.Forms.DataVisualization.dll or System.Web.DataVisualization.dll; in others it’s under System.Web.Extensions or System.Windows.Forms. Use Solution Explorer > Add Reference to add the appropriate assembly.
- In Visual Studio Toolbox, drag the Chart control onto a form or page (Windows Forms: Chart from the Data section; ASP.NET: Chart control).
Basic concepts and object model
The main object is the Chart control. Important sub-objects and concepts:
- ChartAreas: Define a plotting area and its axes. A Chart can contain multiple ChartAreas.
- Series: A collection of data points that share a chart type and rendering style. Each Series has properties such as ChartType, Color, MarkerStyle, XValueType, YValueType.
- DataPoints: Individual points within a Series. They can have X and Y values, labels, colors, and custom attributes.
- Legends: Describe Series and appear outside or inside ChartAreas.
- Titles: Text shown above the chart.
- Annotations: Line, text, image, and callout annotations placed on the chart.
- Tooltips and Labels: Provide interactive or static value displays.
- CustomAttributes: Type-specific attributes for fine-tuned rendering (e.g., point width for a column chart).
Creating a simple Windows Forms chart
Below is an example that creates a basic line chart programmatically.
using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; public class ChartForm : Form { private Chart chart; public ChartForm() { this.Text = "Simple Line Chart"; chart = new Chart { Dock = DockStyle.Fill }; this.Controls.Add(chart); ChartArea area = new ChartArea("MainArea"); chart.ChartAreas.Add(area); Series series = new Series("Sales") { ChartType = SeriesChartType.Line, XValueType = ChartValueType.Int32 }; series.Points.AddXY(2017, 120); series.Points.AddXY(2018, 150); series.Points.AddXY(2019, 170); series.Points.AddXY(2020, 130); series.Points.AddXY(2021, 190); chart.Series.Add(series); chart.Legends.Add(new Legend("Default")); chart.Titles.Add("Annual Sales"); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new ChartForm()); } }
Creating a simple ASP.NET WebForms chart
Add a Chart control to an .aspx page and bind it in code-behind:
ASPX (within
Leave a Reply