Copying, Splitting, and Merging Data in Chart Controls

Some chart types use multiple Y values, such as the Stock chart. Other charts only use the first Y value of each data point, such as the Line chart. When changing the chart type dynamically at run time, you may need to copy, split, and merge Y values.

Copying Data

Use the CopySeriesValues method in the DataManipulator class to copy data from one Y value to another.

Note

Make sure your data is aligned before using the CopySeriesValues method. Otherwise, CopySeriesValues throws an exception. For more information, see Aligning Data.

The following code copies Series1's Y values from Series2's Y2 values.

Chart1.DataManipulator.CopySeriesValues("Series1:Y","Series2:Y2")
Chart1.DataManipulator.CopySeriesValues("Series1:Y","Series2:Y2");

If you only specify the Y value of a series, then the chart uses the first Y value of that series when copying data.

The following code copies Series1's Y values from Series2's Y values.

Chart1.DataManipulator.CopySeriesValues("Series1:Y","Series2")
Chart1.DataManipulator.CopySeriesValues("Series1:Y","Series2");

Merging Data

To merge Y values from multiple series into a single series, use the CopySeriesValues method with a comma-delimited list of series and Y value names for both the input and output parameters.

The following code merges Y values from four series into a series called Stock.

Chart1.DataManipulator.CopySeriesValues("High:Y,Low:Y,Open:Y,Close:Y", "Stock:Y1,Stock:Y2,Stock:Y3,Stock:Y4")
Chart1.DataManipulator.CopySeriesValues("High:Y,Low:Y,Open:Y,Close:Y", "Stock:Y1,Stock:Y2,Stock:Y3,Stock:Y4");

Splitting Data

To split Y values from a single series into multiple series, use the CopySeriesValues method with a comma-delimited list of series and Y value names for both the input and output parameters.

The following code splits Y values from a series into four series.

Chart1.DataManipulator.CopySeriesValues("Stock:Y1,Stock:Y2,Stock:Y3,Stock:Y4", "High:Y,Low:Y,Open:Y,Close:Y")
Chart1.DataManipulator.CopySeriesValues("Stock:Y1,Stock:Y2,Stock:Y3,Stock:Y4", "High:Y,Low:Y,Open:Y,Close:Y");

See Also

Reference

System.Windows.Forms.DataVisualization.Charting

System.Web.UI.DataVisualization.Charting

Concepts

Aligning Data

Filtering Data

Grouping Data

Other Resources

Data Binding and Manipulation