WinForms Chart - Simultaneously Configure Settings for Template Series and Series Added to the Chart Manually
Follow the steps below to implement this scenario:
-
Create a Windows Forms Application in Visual Studio, and add all required assemblies to the References list of your project.
-
Create a chart in the Form1_Load event handler.
-
Populate the chart with autogenerated series:
Use the ChartControl.DataSource property to bind the chart to a data source. The custom GetSeriesTemplateData method returns the chart's data in this example.
Use the ChartControl.SeriesDataMember property to specify the data field that contains series names.
Set the ChartControl.SeriesTemplate.View property to LineSeriesView to generate line series.
-
Call the custom ConfigureSeries method with the ChartControl.SeriesTemplate object passed as a parameter to specify the following settings for all template series: ArgumentDataMember, ValueDataMembers, ArgumentScaleType, ValueScaleType, LabelsVisibility, and Label.TextPattern.
-
Add a single series:
Call the Series(String, ViewType) constructor to create a series. Pass the series name and series type as parameters to this method.
Use the Series.DataSource property to bind the series to a data source. The custom GetSeriesData method returns the series data.
Add the series to the ChartControl.Series collection.
-
Call the custom ConfigureSeries method with the series passed as a parameter to specify series settings.
-
Use the ChartControl.Dock property to specify the chart position. Call the Controls.Add method to add the chart to the form.