aspnet-devexpress-dot-xtracharts-dot-web-dot-webchartcontrol-8d426a93.md
Provides access to the chart control’s collection of series objects.
Namespace : DevExpress.XtraCharts.Web
Assembly : DevExpress.XtraCharts.v25.2.Web.dll
NuGet Package : DevExpress.Web.Visualization
public SeriesCollection Series { get; }
Public ReadOnly Property Series As SeriesCollection
| Type | Description |
|---|---|
| SeriesCollection |
A SeriesCollection object that represents the collection of all series.
|
The Series property provides access to a collection of all series which are defined explicitly within a chart control (either at design time or runtime). The collection is represented by an instance of the SeriesCollection class, and allows individual series (which are instances of the Series class) to be added, deleted and accessed using indexer notation.
Note that series which are bound to data at the level of a web chart control (in particular, using the ASPxDataWebControlBase.DataSource, WebChartControl.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 web chart control’s specific events (such as the WebChartControl.BoundDataChanged event, for instance). To perform a centralized customization of such series, use the settings which are available via the WebChartControl.SeriesTemplate property.
This example shows how to add a web chart control to a web page, create a series and bind it to a data source.
Create an ASP.NET Web Application or open an existing one.
Open the form’s .aspx.cs file. In the Page.Load event handler, create a new WebChartControl class instance and add it to the form’s Controls collection.
Then, create a new series and add it to the chart.
Specify the Series.DataSource property to assign a data source to the series.
Define the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties to specify data source columns that contain point arguments and values.
using System;
using System.Data;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
// ...
namespace WebChartRuntime {
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
// Create a chart.
WebChartControl WebChartControl = new WebChartControl();
// Add the chart to the form.
// Note that a chart isn't initialized until it's added to the form's collection of controls.
this.form1.Controls.Add(WebChartControl);
// Create a new bar series.
Series series = new Series("2017", ViewType.Bar);
// Add the series to the chart.
WebChartControl.Series.Add(series);
// Specify the series data source.
DataTable seriesData = GetData();
series.DataSource = seriesData;
// Specify an argument data member.
series.ArgumentDataMember = "Region";
// Specify a value data member.
series.ValueDataMembers.AddRange(new string[] { "Sales" });
// Rotate the diagram (if necessary).
((XYDiagram)WebChartControl.Diagram).Rotated = true;
}
public DataTable GetData() {
DataTable table = new DataTable();
table.Columns.AddRange(new DataColumn[] {
new DataColumn("Region", typeof(string)),
new DataColumn("Sales", typeof(decimal))
});
table.Rows.Add("Asia", 5.289M);
table.Rows.Add("North America", 4.182M);
table.Rows.Add("Europe", 3.725M);
table.Rows.Add("Australia", 2.272M);
table.Rows.Add("South America", 2.117M);
return table;
}
}
}
Imports System
Imports System.Data
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
Namespace WebChartRuntime
Public Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a chart.
Dim WebChartControl As WebChartControl = New WebChartControl()
' Add the chart to the form.
' Note that a chart isn't initialized until it's added to the form's collection of controls.
Me.form1.Controls.Add(WebChartControl)
' Create a new bar series.
Dim series As Series = New Series("2017", ViewType.Bar)
' Add the series to the chart.
WebChartControl.Series.Add(series)
' Specify the series data source.
Dim seriesData As DataTable = GetData()
series.DataSource = seriesData
' Specify an argument data member.
series.ArgumentDataMember = "Region"
' Specify a value data member.
series.ValueDataMembers.AddRange(New String() {"Sales"})
' Rotate the diagram (if necessary).
(CType(WebChartControl.Diagram, XYDiagram)).Rotated = True
End Sub
Public Function GetData() As DataTable
Dim table As DataTable = New DataTable()
table.Columns.AddRange(New DataColumn() {New DataColumn("Region", GetType(String)), New DataColumn("Sales", GetType(Decimal))})
table.Rows.Add("Asia", 5.289D)
table.Rows.Add("North America", 4.182D)
table.Rows.Add("Europe", 3.725D)
table.Rows.Add("Australia", 2.272D)
table.Rows.Add("South America", 2.117D)
Return table
End Function
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.
asp-net-web-forms-web-chart-control-create-drill-down-chart/CS/DrillDownChart/WebForm1.aspx.cs#L52
if (e.States.Last().Parameters.TryGetValue("ProductCategory", out categoryValue)) {
int seriesIndex = WebChartControl1.Series.IndexOf(WebChartControl1.Series[(string)categoryValue]);
int colorIndex = seriesIndex % WebChartControl1.PaletteRepository[WebChartControl1.PaletteName].Count + 1;
asp-net-web-forms-web-chart-control-create-drill-down-chart/VB/DrillDownChart/WebForm1.aspx.vb#L51
If e.States.Last().Parameters.TryGetValue("ProductCategory", categoryValue) Then
Dim seriesIndex As Integer = WebChartControl1.Series.IndexOf(WebChartControl1.Series(DirectCast(categoryValue, String)))
Dim colorIndex As Integer = seriesIndex Mod WebChartControl1.PaletteRepository(WebChartControl1.PaletteName).Count + 1
See Also