Skip to main content
A newer version of this page is available. .

How to: Display Automatically Created Series in Separate Panes

  • 4 minutes to read

This example demonstrates how to display automatically created series in separate panes.

For this example to work correctly, do the following.

  1. Start MS Visual Studio (2008 or 2010), and create a new Windows Forms Application, or open an existing one.
  2. Include all necessary assemblies to the References list of your project.
  3. 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.

    A dataset (named gspDataSet) is automatically created after performing the above steps.

  4. Drop a button onto the form and add the following code to the Button1.Click event handler.
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraCharts;
using gspDataSetTableAdapters;
// ...

private void button1_Click(object sender, EventArgs e) {
    // Create and customize a form.
    XtraForm form = new XtraForm();
    form.Text = "Multiple Panes and Chart Binding";
    form.Size = new Size(800, 600);

    // Create a chart.
    ChartControl chart = new ChartControl();

    // Handle the chart's BoundDataChanged event.
    chart.BoundDataChanged += new BoundDataChangedEventHandler(chart_BoundDataChanged);

    // Initialize a dataset. Initialize and fill data adapter.
    gspDataSet dataSet = new gspDataSet();
    GSPTableAdapter dataAdapter = new GSPTableAdapter();
    dataAdapter.Fill(dataSet.GSP);

    // Assign the chart's datasource to the created dataset.
    chart.DataSource = dataSet.GSP;
    // Define a data member for the chart's series.
    chart.SeriesDataMember = "Year";
    // Define an argument and value data members for the chart's series template,
    // so that the created series inherit these properties.
    chart.SeriesTemplate.ArgumentDataMember = "Region";
    chart.SeriesTemplate.ValueDataMembers[0] = "GSP";

    // Add the chart to the form's controls collection and fit the chart to the form's dimensions.
    chart.Dock = DockStyle.Fill;
    form.Controls.Add(chart);

    // Show the result.
    form.Show();
}

private void chart_BoundDataChanged(object sender, EventArgs e) {
    ChartControl chart = (ChartControl)sender;

    // Check whether the chart contains series.
    if(chart.Series.Count > 0) {
        // Obtain a diagram and clear its collection of panes.
        XYDiagram diagram = (XYDiagram)chart.Diagram;
        diagram.Panes.Clear();
        // Create a pane for each series.
        for(int i = 1; i < chart.Series.Count; i++) {
            XYDiagramPane pane = new XYDiagramPane("The Pane's Name");
            diagram.Panes.Add(pane);
            XYDiagramSeriesViewBase view = (XYDiagramSeriesViewBase)chart.Series[i].View;
            view.Pane = pane;
        }
    }
}
See Also