http://www.developer.com/net/article.php/3822936/Microsoft-Charts-Overview.htm
Charts are great for displaying information to users in a graphical, tangible way. To support charts in .NET applications, Microsoft provides an add-on for .NET 3.5 SP1 and Visual Studio 2008 to support robust charts without purchasing expensive, proprietary software. In order to create charts like the ones shown in this article, you will need to install Microsoft Chart Controls for Microsoft .NET Framework 3.5 and Microsoft Chart Controls add-on for Microsoft Visual Studio 2008. If you are new to MS Charts, you can check out this overview to help you get started and set up. The following are overviews of the key pieces used in creating and displaying a chart with the MSChart control. The final section is a grouping of tips and tricks that will serve to make your first MSChart experience more enjoyable. The ChartAreas property is a collection of ChartArea objects. A ChartArea is what is responsible for the display properties of the container, or "background," of the chart. Since there can be more than one, this means that a single MSChart control can have multiple charts contained within it. It is important to understand the following when using multiple ChartAreas: Focusing in on a single ChartArea, there are many individual properties that can be set and tweaked to give you the ability to design your chart area to fit many different situations. Most of its properties are similar to those of a Panel control, so we won't cover those. There are others that are unique to the ChartArea. Below is a list of those unique properties.
The Series property, like the ChartAreas property, is a collection. A single Series instance contains 3 important properties: the ChartArea property, the ChartType property, and the Points collection property. Other common used and good-to-know properties on a Series instance include the following: When combining multiple Series instances in a single ChartArea, you are able to easily represent like data points in a comparable manner. For example, the two separate and single charts below each have 6 points of data. Now suppose you wanted to compare the two sets of data points. You could place two MSChart controls next to each other or use two ChartAreas within a chart. While either of those options would work, they would not give you the optimal visual representation of the data. This is why MSChart makes it so simple to combine data points to allow for easy side-by-side comparisons. By adding the data from the second chart as a second Series instance to the first chart we are given a much more visually appealing chart for our comparison. When using multiple Series instances, it is important to keep in mind which ChartType you are using for each Series. Not all ChartType options are compatible together, and others, like the Pie chart for example, don't do a great job at representing separate sets of data. In summary, the chart control's hierarchy is as follows: the MSChart control may have zero to many ChartAreas. A ChartArea may have zero to many Series. A Series may have zero to many DataPoints. Data can be bound at either design-time or run-time. To bind at design-time use the Data Source Configuration Wizard that can be found by clicking on the dropdown button for the DataSource property directly on the MSChart control. If you already have data sources configured, you can select them from the list provided. You can also bind to a data source at run-time through several different methods. There are two different set of methods at different levels in the control that allow binding. One set is on the MSChart control itself and the other is on the Points property of a Series instance. Below is a quick list of the methods and some tips on when to use them.
As far as data sources go, the MSChart control can bind to all objects that implement the IEnumerable interface. This includes, but is not limited to, DataReader, DataSet, Array, and List. It also allows you to bind to SqlCommand, OleDbCommand, SqlDataAdapters, and OleDbDataAdapter objects. The Legends property is again a collection (this time of Legend objects). To quickly grasp what you can do with Legends, think of them as simple table. You have Cells, which make up Cell Columns. By default there are two Cell Columns. As you can see from previous examples, the default settings uses the Series instance name and the color of that Series on the chart. Legends can be extended by adding additional Cell Columns to the CellColumn collection. Column headers can also be added to give more meaning to the legend. In the below example, the headers "Name" and "Color" have been added to a default Legend instance. Legend text for each Series, or the "Name" as used above, is controlled within the Series itself. Use the LegendText property on the individual Series instances to change the text in the chart's legend. You can also give the legend a title. In the example below, the legend is titled "Legend." In addition to just entering the text, you can also set properties to manipulate the title's alignment, color, and font. You will find that most MSChart properties allow for this level of manipulation and customization if you desire. Finally, the chart's legend can be positioned two different ways. You can have the Legend automatically positioned in a docking like fashion. The default is outside the ChartArea, aligned Near, and docked Right. The other option is to manually position it with exact coordinates if your application requires. A variant on the docking option is to dock the legend within the ChartArea. This is done by setting the DockedToChartArea property to the ChartArea object you wish to dock the legend. Titles are like the other previously discussed items. You create individual instances of a Title and the chart control holds a collection of these Title instances in the Titles collection. The simplest way to think about a Title is as a Label control that is internally docked within a panel that itself is docked within the chart control. This means that you can have your title to be top-centered, left- centered, top-left, right-bottom, and the list could go on and on. The only "docking" functionality you may be familiar with that is unavailable is "Fill." In the below example, a bold Title with a font size of 12 has been added to the chart called "My First Chart." The Microsoft Chart Controls offer robust, flexible, customizable chart controls for displaying information to your users in the most easily digestible ways. We have covered the chart properties at a high level. Now you can go out and start creating charts to wow your application users. Matt Goebel is a manager with Crowe Horwath LLP in the Indianapolis, Indiana, office. He can be reached at 317.208.2555 or matt .goebel@crowehorwath.com. Rachel Baker is a senior developer with Crowe Horwath LLP in the Oak Brook, Illinois, office. She can be reached at 630.990.4434 or rachel .baker@crowehorwath.com.
Microsoft Charts Overview
June 4, 2009
Introduction
ChartAreas
Click here for larger image
Figure 1.1 - Single and multiple ChartArea(s)
Click here for larger image
Figure 1.2 3D styling Series
Figure 1.3 Y-value data labels
Click here for larger image
Figure 1.4 Separate data series
Figure 1.5 Combined data series Data Binding
Chart Methods:
Points Methods:
Legends
Click here for larger image
Figure 1.6 Simple legend
Click here for larger image
Figure 1.7 More complex legendTitles
Figure 1.8 Chart with a customized title Tips and Tricks
chart1.Series["Series1"].Color = Color.FromArgb(220, 123, 123, 123);
(chart1.Series["Series1"]
, chart1.Series["Series2"]
) is more logical and therefore less likely to introduce errors than (chart1.Series["salesrepearningquarter"]
, chart1.Series["salesrepcomdatabyquarter"]
). Conclusion
About the Authors