Series and Data Points
The Chart.Series collection contains all data series (Series objects) in the Chart control. Each series is assigned the following:
A chart type (the Series.ChartType property)
A chart area (the Series.ChartArea property)
A legend (the Series.Legend property), if applicable
An X axis (the Series.XAxisType property)
A Y axis (the Series.XAxisType property)
Each series contains a collection of DataPoint objects (the Series.Points collection property). Each data point contains:
An X value (the DataPoint.XValue property)
One or more Y values (the DataPoint.YValues property)
The Series and DataPoint objects contain appearance properties for labels, markers, and empty points. For more information, see Chart Appearance.
When you set these properties in a series, all data points in the series inherit the same settings. If you set properties in a particular data point, the settings take precedence over the settings in the series.
Adding Series and Data at Run Time
To add a series to the Chart control at run time, use the Add method in the Chart.Series collection property. To add a data point to a series at run time, use the Add, AddXY, and AddY methods in the Series.Points collection property.
The following code adds a column type series to the chart picture, adds a data point, and plots it in ChartArea1.
Plotting Multiple Series in a Chart Area
When you assign multiple series to the same chart area, the chart area attempts to plot the series together. It uses the following techniques:
- Series with chart types that can be stacked are stacked one on top of the other. For example, the Stacked Bar Chart.
- Series that can be plotted next to one another are plotted side by side. For example, the Bar Chart.
- If series are with chart types that cannot be stacked or clustered, they overlap one another according to their index order in the Chart.Series collection. The series at index 0 is plotted first, and then the series at index 1 overlaps it, and so on.
|Circular-shaped chart types and pyramid and funnel chart types allow only one series per chart area. All other chart types can each be plotted with compatible chart types. For more information, see Chart Types.|
To ensure the correct overlap when plotting series together, make sure that the series you want to appear in the front has a larger index number than the other series in the Chart.Series collection.
Indexing X Values
You can index the X values of a series in the plot area. By default, the Chart control plots a series in the ascending order of the X values. If you set the Series.IsXValueIndexed property to true, the Chart control uses the index order of the data points in the Series.Points collection property instead.
This is useful when the series' X values are not important and you do not want to see gaps in the plotted data due to the gaps in the X values.
|Setting the Series.IsXValueIndexed property to true causes all series assigned to the same chart area and X axis (primary or secondary) to be indexed. You must make sure that the series are aligned. Otherwise, the Chart control throws an exception. For more information, see Aligning Data.|
You can use keywords for labels, legends, and tooltips in a series or in a data point, such as the Series.Tooltip property. For more information on keywords, see Keywords.
Using Custom Properties
Depending on the chart type you choose for a series, you can access certain custom properties to customize how the data series is plotted. To do this, use the CustomProperties property in the Series or DataPoint object. For more information, see Custom Properties.