windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-e7639a03.md
Provides access to the chart control’s collection of series objects.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.UI.dll
NuGet Package : DevExpress.Win.Charts
public SeriesCollection Series { get; }
Public ReadOnly Property Series As SeriesCollection
| Type | Description |
|---|---|
| SeriesCollection |
The collection of series that the Chart Control displays.
|
The Series property provides access to a collection of all series that the Chart Control displays. The property manages (adds, removes, accesses using indexer notation, etc.) chart’s series that the Series class objects represent.
Note that series which are bound to data at the level of a chart control (in particular, using the ChartControl.DataSource, ChartControl.SeriesDataMember and both the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties) are created dynamically based upon the data obtained from the specified data source and they are not presented within the Series collection. In order to access such series use the CustomDrawSeriesEventArgsBase.Series property of a chart control’s specific events (such as the ChartControl.CustomDrawSeries or ChartControl.CustomDrawSeriesPoint event, for instance). To perform a centralized customization of such series use the settings which are available via the ChartControl.SeriesTemplate property.
This example demonstrates how to create a ChartControl with two series of the SideBySideBarSeriesView type and bind them to a data source:
Add a chart to the WinForms project and specify the chart’s data source.
Create two series and add them to the chart.
Configure series view settings.
using DevExpress.XtraCharts;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
// ...
namespace SideBySideBar2D {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl chart = new ChartControl();
// Bind a chart to a data source.
chart.DataSource = DataPoint.GetDataPoints();
// Create the first series and specify its data members.
Series series1 = new Series("2018", ViewType.Bar);
series1.ArgumentDataMember = "Region";
series1.ValueDataMembers.AddRange("Value1");
// Create the second series and specify its data members.
Series series2 = new Series("2019", ViewType.Bar);
series2.ArgumentDataMember = "Region";
series2.ValueDataMembers.AddRange("Value2");
// Add series to the chart.
chart.Series.AddRange(new Series[] { series1, series2 });
// Change the first series's view settings.
SideBySideBarSeriesView view1 = series1.View as SideBySideBarSeriesView;
// The BarDistance, BarDistanceFixed, and EqualBarWidth property values are synchronized
// in all Side-by-Side Bar Series in a ChartControl.
// So, you can specify them only for one series view.
view1.BarDistance = 0.1;
view1.BarDistanceFixed = 2;
view1.BarWidth = 0.4;
view1.EqualBarWidth = true;
view1.Color = Color.MediumSeaGreen;
// Change the second series's view settings.
SideBySideBarSeriesView view2 = series2.View as SideBySideBarSeriesView;
view2.BarWidth = 0.4;
view2.Color = Color.MediumVioletRed;
// Change the legend position.
chart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
chart.Legend.AlignmentVertical = LegendAlignmentVertical.Bottom;
// Rotate the diagram.
((XYDiagram)chart.Diagram).Rotated = true;
// Configure the x-axis appearance.
((XYDiagram)chart.Diagram).AxisX.Tickmarks.MinorVisible = false;
((XYDiagram)chart.Diagram).AxisX.Reverse = true;
// Add a title to the chart.
ChartTitle chartTitle1 = new ChartTitle();
chartTitle1.Text = "Sales by Region";
chart.Titles.Add(chartTitle1);
// Add the chart to the form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
}
public class DataPoint {
public string Region { get; set; }
public double Value1 { get; set; }
public double Value2 { get; set; }
public DataPoint(string region, double value1, double value2) {
this.Region = region;
this.Value1 = value1;
this.Value2 = value2;
}
public static BindingList<DataPoint> GetDataPoints() {
BindingList<DataPoint> data = new BindingList<DataPoint> {
new DataPoint("Asia", 4.7685, 5.289),
new DataPoint("Australia", 1.9576, 2.2727),
new DataPoint("Europe", 3.0884, 3.7257),
new DataPoint("North America", 3.7477, 4.1825),
new DataPoint("South America", 1.8945, 2.1172),
};
return data;
}
}
}
Imports DevExpress.XtraCharts
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace SideBySideBar2D
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create an empty chart.
Dim chart As ChartControl = New ChartControl
' Bind a chart to a data source.
chart.DataSource = DataPoint.GetDataPoints
' Create the first series and specify its data members.
Dim series1 As Series = New Series("2018", ViewType.Bar)
series1.ArgumentDataMember = "Region"
series1.ValueDataMembers.AddRange("Value1")
' Create the second series and specify its data members.
Dim series2 As Series = New Series("2019", ViewType.Bar)
series2.ArgumentDataMember = "Region"
series2.ValueDataMembers.AddRange("Value2")
' Add series to the chart.
chart.Series.AddRange(New Series() {series1, series2})
' Change the first series's view settings.
Dim view1 As SideBySideBarSeriesView = TryCast(series1.View, SideBySideBarSeriesView)
' The BarDistance, BarDistanceFixed, and EqualBarWidth property values are synchronized
' in all Side-by-Side Bar Series in a ChartControl.
' So, you can specify them only for one series view.
view1.BarDistance = 0.1
view1.BarDistanceFixed = 2
view1.BarWidth = 0.4
view1.EqualBarWidth = True
view1.Color = Color.MediumSeaGreen
' Change the second series's view settings.
Dim view2 As SideBySideBarSeriesView = TryCast(series2.View, SideBySideBarSeriesView)
view2.BarWidth = 0.4
view2.Color = Color.MediumVioletRed
' Change the legend position.
chart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right
chart.Legend.AlignmentVertical = LegendAlignmentVertical.Bottom
' Rotate the diagram.
CType(chart.Diagram, XYDiagram).Rotated = True
' Configure the x-axis appearance.
CType(chart.Diagram, XYDiagram).AxisX.Tickmarks.MinorVisible = False
CType(chart.Diagram, XYDiagram).AxisX.Reverse = True
' Add a title to the chart.
Dim chartTitle1 As ChartTitle = New ChartTitle
chartTitle1.Text = "Sales by Region"
chart.Titles.Add(chartTitle1)
' Add the chart to the form.
chart.Dock = DockStyle.Fill
Me.Controls.Add(chart)
End Sub
End Class
Public Class DataPoint
Public Property Region As String
Public Property Value1 As Double
Public Property Value2 As Double
Public Sub New(ByVal region As String, ByVal value1 As Double, ByVal value2 As Double)
Me.Region = region
Me.Value1 = value1
Me.Value2 = value2
End Sub
Public Shared Function GetDataPoints() As BindingList(Of DataPoint)
Dim data As BindingList(Of DataPoint) = New BindingList(Of DataPoint) From {
New DataPoint("Asia", 4.7685, 5.289),
New DataPoint("Australia", 1.9576, 2.2727),
New DataPoint("Europe", 3.0884, 3.7257),
New DataPoint("North America", 3.7477, 4.1825),
New DataPoint("South America", 1.8945, 2.1172)
}
Return data
End Function
End Class
End Namespace
The following example demonstrates how to create a ChartControl with two series of the SideBySideBarSeriesView type, and add this chart to a form at runtime. Before proceeding with this example, first create a Windows Forms Application in Visual Studio, and include all necessary assemblies to the References list of your project.
Then, add the following code to the Form.Load event handler.
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace SideBySideBar2D {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Create an empty chart.
ChartControl sideBySideBarChart = new ChartControl();
// Create the first side-by-side bar series and add points to it.
Series series1 = new Series("Side-by-Side Bar Series 1", ViewType.Bar);
series1.Points.Add(new SeriesPoint("A", 10));
series1.Points.Add(new SeriesPoint("B", 12));
series1.Points.Add(new SeriesPoint("C", 14));
series1.Points.Add(new SeriesPoint("D", 17));
// Create the second side-by-side bar series and add points to it.
Series series2 = new Series("Side-by-Side Bar Series 2", ViewType.Bar);
series2.Points.Add(new SeriesPoint("A", 15));
series2.Points.Add(new SeriesPoint("B", 18));
series2.Points.Add(new SeriesPoint("C", 25));
series2.Points.Add(new SeriesPoint("D", 33));
// Add the series to the chart.
sideBySideBarChart.Series.Add(series1);
sideBySideBarChart.Series.Add(series2);
// Hide the legend (if necessary).
sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
// Rotate the diagram (if necessary).
((XYDiagram)sideBySideBarChart.Diagram).Rotated = true;
// Add a title to the chart (if necessary).
ChartTitle chartTitle1 = new ChartTitle();
chartTitle1.Text = "Side-by-Side Bar Chart";
sideBySideBarChart.Titles.Add(chartTitle1);
// Add the chart to the form.
sideBySideBarChart.Dock = DockStyle.Fill;
this.Controls.Add(sideBySideBarChart);
}
}
}
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Namespace SideBySideBar2D
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Create an empty chart.
Dim sideBySideBarChart As New ChartControl()
' Create the first side-by-side bar series and add points to it.
Dim series1 As New Series("Side-by-Side Bar Series 1", ViewType.Bar)
series1.Points.Add(New SeriesPoint("A", 10))
series1.Points.Add(New SeriesPoint("B", 12))
series1.Points.Add(New SeriesPoint("C", 14))
series1.Points.Add(New SeriesPoint("D", 17))
' Create the second side-by-side bar series and add points to it.
Dim series2 As New Series("Side-by-Side Bar Series 2", ViewType.Bar)
series2.Points.Add(New SeriesPoint("A", 15))
series2.Points.Add(New SeriesPoint("B", 18))
series2.Points.Add(New SeriesPoint("C", 25))
series2.Points.Add(New SeriesPoint("D", 33))
' Add the series to the chart.
sideBySideBarChart.Series.Add(series1)
sideBySideBarChart.Series.Add(series2)
' Hide the legend (if necessary).
sideBySideBarChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False
' Rotate the diagram (if necessary).
CType(sideBySideBarChart.Diagram, XYDiagram).Rotated = True
' Add a title to the chart (if necessary).
Dim chartTitle1 As New ChartTitle()
chartTitle1.Text = "Side-by-Side Bar Chart"
sideBySideBarChart.Titles.Add(chartTitle1)
' Add the chart to the form.
sideBySideBarChart.Dock = DockStyle.Fill
Me.Controls.Add(sideBySideBarChart)
End Sub
End Class
End Namespace
The following code snippets (auto-collected from DevExpress Examples) contain references to the Series property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-charts-show-chart-legend-with-markers-in-separate-control/CS/Form1.cs#L18
CreateLegendMarkers(chart);
gridControl1.DataSource = chart.Series;
}
winforms-charts-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/CS/Form1.cs#L43
void ChartControl1_BoundDataChanged(object sender,EventArgs e) {
Series series = chartControl1.Series[0];
var argTotalDict = new Dictionary<string,double>();
winforms-charts-change-series-line-color-when-value-is-under-predefined-level/CS/Form1.cs#L37
level = Convert.ToDouble(textBox1.Text);
Series series = chartControl1.Series[0];
StepLineSeriesView view = new StepLineSeriesView();
winforms-dashboard-obtain-dashboard-item-client-data/CS/Dashboard_ClientDataCards_Win/Form1.cs#L69
foreach (Series series in chart.Series) {
series.DataSource = dataSource; series.ArgumentDataMember = "Argument";
MultiPaneSettings settings = MultiPaneSettings.FromJson(chartItem.CustomProperties[customPropertyName]);
CustomizeDiagram(e.ChartControl.Diagram as XYDiagram, e.ChartControl.Series, settings);
}
winforms-charts-show-chart-legend-with-markers-in-separate-control/VB/Form1.vb#L19
CreateLegendMarkers(chart)
gridControl1.DataSource = chart.Series
End Sub
winforms-chart-exclude-weekends-and-holidays-from-the-axis-range/VB/WeekendsExclusion/Form1.vb#L17
#Region "OriginalChart"
Dim series0 As Series = chartControl0.Series(0)
series0.ArgumentScaleType = ScaleType.DateTime
winforms-charts-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/VB/Form1.vb#L43
Private Sub ChartControl1_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim series As Series = chartControl1.Series(0)
Dim argTotalDict = New Dictionary(Of String, Double)()
winforms-charts-change-series-line-color-when-value-is-under-predefined-level/VB/Form1.vb#L42
level = Convert.ToDouble(textBox1.Text)
Dim series As Series = chartControl1.Series(0)
Dim view As StepLineSeriesView = New StepLineSeriesView()
winforms-dashboard-obtain-dashboard-item-client-data/VB/Dashboard_ClientDataCards_Win/Form1.vb#L68
For Each series As Series In chart.Series
series.DataSource = dataSource
See Also