windowsforms-4943-controls-and-libraries-chart-control-examples-creating-charts-providing-data-how-to-bind-series-to-data-and-display-them-in-separate-panes-runtime-sample.md
This example demonstrates how to display a chart’s series in separate panes.
For this example to work correctly, do the following.
Start MS Visual Studio, and create a new Windows Forms Application , or open an existing one.
Include all necessary assemblies to the References list of your project.
Open the Solution Explorer window (e.g. by pressing CTRL+ALT+L), right-click the WindowsApplication1 item and in the invoked menu, point to Add and click Existing Item…. Then, locate the gsp.mdb file (it is shipped with XtraCharts suite and located in the directory, where you installed DevExpress demos) and click Add. In the displayed dialog, select the GSP table of this database.
Drop a button onto the form and add the following code to the Button1.Click event handler.
using System;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
namespace TwoBoundSeriesInPanes {
public partial class MainForm : XtraForm {
public MainForm() {
InitializeComponent();
// This line of code is generated by Data Source Configuration Wizard
gspTableAdapter.Fill(gspDataSet.GSP);
}
private void OnFormLoad(object sender, EventArgs e)
{
Series year2003Series = new Series();
year2003Series.Name = "2003";
year2003Series.ArgumentDataMember = "Region";
year2003Series.ValueDataMembers[0] = "GSP";
year2003Series.FilterString = @"[Year] == 2003";
Series year2004Series = new Series();
year2004Series.Name = "2004";
year2004Series.ArgumentDataMember = "Region";
year2004Series.ValueDataMembers[0] = "GSP";
year2004Series.FilterString = @"[Year] == 2004";
chartControl.Series.AddRange(year2003Series, year2004Series);
XYDiagram diagram = (XYDiagram)chartControl.Diagram;
XYDiagramPane secondPane = new XYDiagramPane("Second Pane");
diagram.Panes.Add(secondPane);
Legend secondLegend = new Legend("Second Legend") {
DockTarget = secondPane,
AlignmentHorizontal = LegendAlignmentHorizontal.Right,
AlignmentVertical = LegendAlignmentVertical.Top
};
chartControl.Legends.Add(secondLegend);
XYDiagramSeriesViewBase xyView = (XYDiagramSeriesViewBase)year2004Series.View;
year2004Series.Legend = secondLegend;
xyView.Pane = secondPane;
}
}
}
Imports System
Imports DevExpress.XtraCharts
Imports DevExpress.XtraEditors
Namespace TwoBoundSeriesInPanes
Partial Public Class MainForm
Inherits XtraForm
Public Sub New()
InitializeComponent()
' This line of code is generated by Data Source Configuration Wizard
gspTableAdapter.Fill(gspDataSet.GSP)
End Sub
Private Sub OnFormLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim year2003Series As New Series()
year2003Series.Name = "2003"
year2003Series.ArgumentDataMember = "Region"
year2003Series.ValueDataMembers(0) = "GSP"
year2003Series.FilterString = "[Year] == 2003"
Dim year2004Series As New Series()
year2004Series.Name = "2004"
year2004Series.ArgumentDataMember = "Region"
year2004Series.ValueDataMembers(0) = "GSP"
year2004Series.FilterString = "[Year] == 2004"
chartControl.Series.AddRange(year2003Series, year2004Series)
Dim diagram As XYDiagram = CType(chartControl.Diagram, XYDiagram)
Dim secondPane As New XYDiagramPane("Second Pane")
diagram.Panes.Add(secondPane)
Dim secondLegend As New Legend("Second Legend") With { _
.DockTarget = secondPane, _
.AlignmentHorizontal = LegendAlignmentHorizontal.Right, _
.AlignmentVertical = LegendAlignmentVertical.Top _
}
chartControl.Legends.Add(secondLegend)
Dim xyView As XYDiagramSeriesViewBase = CType(year2004Series.View, XYDiagramSeriesViewBase)
year2004Series.Legend = secondLegend
xyView.Pane = secondPane
End Sub
End Class
End Namespace
See Also