Getting Started with Microsoft Chart Controls for .NET Framework 3.5Microsoft Chart Controls for .NET Framework 3.5 provide a powerful, flexible way to add charts and data visualizations to Windows Forms and ASP.NET applications. Introduced as an add-on to .NET 3.5, these controls deliver a wide range of chart types, rich styling options, data-binding capabilities, and export features. This guide walks through installation, basic usage, common chart types, data binding, formatting, interactivity, and deployment considerations so you can start visualizing data quickly and effectively.
What are Microsoft Chart Controls?
Microsoft Chart Controls for .NET Framework 3.5 are a set of charting components built on top of the .NET Framework that enable developers to render 2D and 3D charts in Windows Forms and ASP.NET applications. They support a large number of chart types (line, bar, pie, area, candlestick, stock, radar, polar, bubble, scatter, and more), customizable axes, legends, titles, annotations, tooltips, and image export formats (PNG, JPEG, GIF).
Installation and Requirements
- .NET Framework: 3.5 SP1 (recommended)
- Download: The Chart Controls were distributed as an add-on package and via the Microsoft Web Platform Installer. For development, you’ll need the Chart Controls assembly and, for ASP.NET, the Chart HTTP handler/module registration.
To install:
- Install .NET Framework 3.5 SP1 if not already present.
- Download and install “Microsoft Chart Controls for Microsoft .NET Framework 3.5” and the “Chart Controls Add-on for Microsoft Visual Studio 2008” if you want design-time support.
- For ASP.NET applications, add the chart HTTP handler to web.config (if required) or use the integrated support available in later updates.
Assemblies to reference:
- System.Web.DataVisualization (for ASP.NET)
- System.Windows.Forms.DataVisualization (for Windows Forms)
First Steps: Creating a Simple Chart (Windows Forms)
- Create a new Windows Forms project targeting .NET Framework 3.5.
- Add a reference to System.Windows.Forms.DataVisualization.
- From the Toolbox (after installing the Visual Studio add-on) drag a Chart control onto the form, or instantiate one in code.
Example (C#):
using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; public class MainForm : Form { public MainForm() { var chart = new Chart { Dock = DockStyle.Fill }; var chartArea = new ChartArea("MainArea"); chart.ChartAreas.Add(chartArea); var series = new Series("Sales") { ChartType = SeriesChartType.Column }; series.Points.AddXY("Jan", 100); series.Points.AddXY("Feb", 120); series.Points.AddXY("Mar", 140); chart.Series.Add(series); chart.Legends.Add(new Legend("MainLegend")); Controls.Add(chart); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new MainForm()); } }
This example produces a simple column chart with three data points and a legend.
First Steps: Creating a Simple Chart (ASP.NET WebForms)
- Create an ASP.NET Web Forms project targeting .NET 3.5.
- Add reference to System.Web.DataVisualization and include the Chart control on an .aspx page.
Example markup:
<%@ Register Assembly="System.Web.DataVisualization" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %> <asp:Chart ID="Chart1" runat="server" Width="600px" Height="400px"> <Series> <asp:Series Name="Series1" ChartType="Line"></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"></asp:ChartArea> </ChartAreas> </asp:Chart>
Code-behind (C#):
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Chart1.Series["Series1"].Points.AddXY("Jan", 100); Chart1.Series["Series1"].Points.AddXY("Feb", 120); Chart1.Series["Series1"].Points.AddXY("Mar", 140); } }
Chart Types Overview
Commonly used chart types include:
- Line: trend over continuous values.
- Column / Bar: categorical comparisons.
- Pie / Doughnut: parts of a whole.
- Area / StackedArea: cumulative trends.
- Scatter / Bubble: XY plots, bubble adds size dimension.
- Candlestick / Stock: financial data with open/high/low/close.
- Radar / Polar: multivariate comparisons.
Choose chart type based on data characteristics: use line for time-series, bar for categories, pie only for a small number of parts.
Data Binding and Dynamic Data
Charts support data binding to collections, DataTables, arrays, and custom objects.
Example binding to a List
public class SalesRecord { public string Month { get; set; } public int Value { get; set; } } var records = new List<SalesRecord> { new SalesRecord { Month = "Jan", Value = 100 }, new SalesRecord { Month = "Feb", Value = 120 } }; chart.Series["Sales"].XValueMember = "Month"; chart.Series["Sales"].YValueMembers = "Value"; chart.DataSource = records; chart.DataBind();
For large data sets, consider performance: reduce point markers, enable fast drawing modes, or sample/aggregate data.
Styling, Labels, and Formatting
- Axes: Configure LabelStyle, Interval, Title, and grid lines via ChartArea.AxisX / AxisY.
- Legends/Titles: Use Legend and Title objects for descriptions.
- Data point labels: Series.Points[].Label or Series.Label to show values; use formatting strings like “#,##0” or “P0” (percent).
- Colors and palettes: Use series.Color, series.BackSecondaryColor, Chart.Palette or custom palettes.
Example: show formatted Y-axis and rotate X labels:
chart.ChartAreas["MainArea"].AxisY.LabelStyle.Format = "N0"; chart.ChartAreas["MainArea"].AxisX.LabelStyle.Angle = -45;
Interactivity: Tooltips, Clicks, and Zooming
- Tooltips: set Series.ToolTip or Points.ToolTip to display on hover.
- Click events: handle Chart.MouseClick or Series.Points[].Tag and Chart.GetHitTest to determine clicked point.
- Zoom and pan: enable Axis.ScaleView.Zoom and use Axis.ScrollBar for navigation.
Example tooltip:
series.ToolTip = "#VALX: #VALY";
Annotations and Custom Drawing
Use Annotation objects (TextAnnotation, LineAnnotation, RectangleAnnotation) to add notes or highlight regions. Custom drawing can be performed by handling the PostPaint events for fine-grained control.
Exporting and Printing
Charts can be exported to images:
chart.SaveImage("chart.png", ChartImageFormat.Png);
For ASP.NET, write image to Response or configure the image handler to stream charts.
Localization and Accessibility
- Localize labels, legends, and title strings.
- Ensure accessibility by providing alternative text and using clear color contrasts. The Chart control supports setting AccessibleDescription and AccessibleName.
Common Pitfalls & Troubleshooting
- Missing assemblies or wrong target framework: ensure references are to the 3.5 Chart assemblies.
- ASP.NET handler not configured: check web.config chart handler settings if images don’t render.
- Performance issues with many points: reduce markers, enable fast rendering, aggregate data.
- Design-time Toolbox missing: install the Visual Studio Chart Add-on for design-time support.
Deployment Considerations
- Include relevant assemblies (System.Web.DataVisualization or System.Windows.Forms.DataVisualization) with your deployment if target machines might lack them.
- For web applications, ensure the Chart image handler works under your hosting environment and write permissions are available if using temporary file storage.
- Test under target .NET Framework 3.5 SP1 runtime.
Example: Building a Small Dashboard
A simple dashboard might include:
- A line chart for monthly revenue.
- A column chart for top-selling products.
- A pie chart for market share. Bind each chart to distinct data sources, reuse ChartArea and style templates, and expose tooltips and zoom for deeper inspection.
Resources & Further Reading
- API documentation for System.Windows.Forms.DataVisualization and System.Web.UI.DataVisualization namespaces.
- Samples shipped with the Chart Controls add-on illustrate many scenarios like financial, real-time, and multi-series charts.
Microsoft Chart Controls for .NET Framework 3.5 remain a solid option for adding rich charts to legacy .NET applications. They combine broad chart type support, flexible styling, data binding, and export capabilities—enabling you to build informative visualizations with moderate effort.