Back to Devexpress

ChartControl.BoundDataChanged Event

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-f55c141c.md

latest15.2 KB
Original Source

ChartControl.BoundDataChanged Event

Occurs every time a chart control generates its series points from the underlying data source.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public event BoundDataChangedEventHandler BoundDataChanged
vb
Public Event BoundDataChanged As BoundDataChangedEventHandler

Event Data

The BoundDataChanged event's data class is EventArgs.

Remarks

You can handle this event to change the way in which chart data is plotted before the chart displays it. In general, this event should be used to change a series’ SeriesBase.Visible property, or to change any properties of series labels or a series view type.

View Example: Hide Specific Series

Note

Note that not all series’ properties can be changed in the BoundDataChanged event handler. For example, changing the following properties will have no effect:

For a code example, refer to How to: Individually Change the View Type of Automatically Created Series.

For more information, refer to Generate Series from a Data Source.

Note

When auto-bridging a chart with Pivot Grid, the BoundDataChanged event is raised after automatic settings are applied to the axes, legend, and some other elements. To learn more on these options, see Pivot Charting (Integration with a Pivot Grid Control).

Example

This example demonstrates how an auto-created series (a series generated automatically based on the series template settings) can be accessed at runtime, to individually change its view type.

This is performed in a special ChartControl.BoundDataChanged event of the chart control.

csharp
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

namespace ChangeViewOfAnAutoSeries {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private DataTable CreateChartData() {
            // Create an empty table.
            DataTable table = new DataTable("Table1");

            // Add three columns to the table.
            table.Columns.Add("Month", typeof(String));
            table.Columns.Add("Section", typeof(String));
            table.Columns.Add("Value", typeof(Int32));

            // Add data rows to the table.
            table.Rows.Add(new object[] { "Jan", "Section1", 10 });
            table.Rows.Add(new object[] { "Jan", "Section2", 20 });
            table.Rows.Add(new object[] { "Jan", "Section3", 40 });
            table.Rows.Add(new object[] { "Feb", "Section1", 20 });
            table.Rows.Add(new object[] { "Feb", "Section2", 30 });
            table.Rows.Add(new object[] { "Feb", "Section3", 80 });
            table.Rows.Add(new object[] { "March", "Section1", 30 });
            table.Rows.Add(new object[] { "March", "Section2", 40 });
            table.Rows.Add(new object[] { "March", "Section3", 100 });

            return table;
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create a chart.
            ChartControl chart = new ChartControl();

            // Generate a data table and bind the chart to it.
            chart.DataSource = CreateChartData();

            // Specify data members to bind the chart's series template.
            chart.SeriesDataMember = "Month";
            chart.SeriesTemplate.ArgumentDataMember = "Section";
            chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });

            // Specify the template's series view.
            chart.SeriesTemplate.View = new SideBySideBarSeriesView();

            // Specify the BoundDataChanged event handler.
            chart.BoundDataChanged +=
                new BoundDataChangedEventHandler(chart_BoundDataChanged);

            // Specify the template's name prefix.
            chart.SeriesNameTemplate.BeginText = "Month: ";

            // Dock the chart into its parent, and add it to the current form.
            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }

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

            // Change the view of the "Month: Feb" series from 
            // SideBySideBarSeriesView to LineSeriesView.
            Series feb = chart.GetSeriesByName("Month: Feb");
            if (feb != null)
                feb.ChangeView(ViewType.Line);

            // Change the view of the "Month: March" series from 
            // SideBySideBarSeriesView to SplineSeriesView.
            Series march = chart.GetSeriesByName("Month: March");
            if (march != null)
                march.ChangeView(ViewType.Spline);
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Namespace ChangeViewOfAnAutoSeries
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Function CreateChartData() As DataTable
            ' Create an empty table.
            Dim table As New DataTable("Table1")

            ' Add three columns to the table.
            table.Columns.Add("Month", GetType(String))
            table.Columns.Add("Section", GetType(String))
            table.Columns.Add("Value", GetType(Int32))

            ' Add data rows to the table.
            table.Rows.Add(New Object() { "Jan", "Section1", 10 })
            table.Rows.Add(New Object() { "Jan", "Section2", 20 })
            table.Rows.Add(New Object() { "Jan", "Section3", 40 })
            table.Rows.Add(New Object() { "Feb", "Section1", 20 })
            table.Rows.Add(New Object() { "Feb", "Section2", 30 })
            table.Rows.Add(New Object() { "Feb", "Section3", 80 })
            table.Rows.Add(New Object() { "March", "Section1", 30 })
            table.Rows.Add(New Object() { "March", "Section2", 40 })
            table.Rows.Add(New Object() { "March", "Section3", 100 })

            Return table
        End Function

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create a chart.
            Dim chart As New ChartControl()

            ' Generate a data table and bind the chart to it.
            chart.DataSource = CreateChartData()

            ' Specify data members to bind the chart's series template.
            chart.SeriesDataMember = "Month"
            chart.SeriesTemplate.ArgumentDataMember = "Section"
            chart.SeriesTemplate.ValueDataMembers.AddRange(New String() { "Value" })

            ' Specify the template's series view.
            chart.SeriesTemplate.View = New SideBySideBarSeriesView()

            ' Specify the BoundDataChanged event handler.
            AddHandler chart.BoundDataChanged, AddressOf chart_BoundDataChanged

            ' Specify the template's name prefix.
            chart.SeriesNameTemplate.BeginText = "Month: "

            ' Dock the chart into its parent, and add it to the current form.
            chart.Dock = DockStyle.Fill
            Me.Controls.Add(chart)
        End Sub

        Private Sub chart_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim chart As ChartControl = CType(sender, ChartControl)

            ' Change the view of the "Month: Feb" series from 
            ' SideBySideBarSeriesView to LineSeriesView.
            Dim feb As Series = chart.GetSeriesByName("Month: Feb")
            If feb IsNot Nothing Then
                feb.ChangeView(ViewType.Line)
            End If

            ' Change the view of the "Month: March" series from 
            ' SideBySideBarSeriesView to SplineSeriesView.
            Dim march As Series = chart.GetSeriesByName("Month: March")
            If march IsNot Nothing Then
                march.ChangeView(ViewType.Spline)
            End If
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the BoundDataChanged event.

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-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/CS/Form1.cs#L24

csharp
chartControl1.BoundDataChanged += ChartControl1_BoundDataChanged;
}

winforms-charts-create-a-side-by-side-stacked-bars/CS/SideBySideStackedBarChart/Form1.cs#L42

csharp
chart.BoundDataChanged += Chart_BoundDataChanged;
}

winforms-charts-apply-the-best-fit-function-to-a-series/CS/LineOfBestFit/Form1.cs#L81

csharp
textBox1.Text = r.ToString();
    chartControl1.BoundDataChanged += chartControl1_BoundDataChanged;
}

winforms-chart-draw-a-custom-legend-marker-for-a-series-point/CS/CustomSeriesPointDrawingSample/Form1.cs#L42

csharp
chart.CustomDrawSeriesPoint += OnCustomDrawSeriesPoint;
chart.BoundDataChanged += OnBoundDataChanged;
chart.ObjectHotTracked += OnObjectHotTracked;

winforms-charts-change-series-line-color-when-value-is-under-predefined-level/CS/Form1.cs#L20

csharp
private void Form1_Load(object sender, EventArgs e) {
    chartControl1.BoundDataChanged += OnBoundDataChanged;
    InitializeSeries();

winforms-charts-sort-stacked-bars-by-total-values-with-qualitativescalecomparer/VB/Form1.vb#L24

vb
stackedBarSeriesView.Pane.StackedBarTotalLabel.Visible = True
    AddHandler chartControl1.BoundDataChanged, AddressOf ChartControl1_BoundDataChanged
End Sub

winforms-charts-create-a-side-by-side-stacked-bars/VB/SideBySideStackedBarChart/Form1.vb#L41

vb
diagram.AxisY.WholeRange.AlwaysShowZeroLevel = False
    AddHandler chart.BoundDataChanged, AddressOf Chart_BoundDataChanged
End Sub

winforms-charts-apply-the-best-fit-function-to-a-series/VB/LineOfBestFit/Form1.vb#L89

vb
textBox1.Text = r.ToString()
    AddHandler chartControl1.BoundDataChanged, AddressOf chartControl1_BoundDataChanged
End Sub

winforms-chart-draw-a-custom-legend-marker-for-a-series-point/VB/CustomSeriesPointDrawingSample/Form1.vb#L47

vb
AddHandler Me.chart.CustomDrawSeriesPoint, AddressOf Me.OnCustomDrawSeriesPoint
AddHandler Me.chart.BoundDataChanged, AddressOf Me.OnBoundDataChanged
AddHandler Me.chart.ObjectHotTracked, AddressOf Me.OnObjectHotTracked

winforms-charts-change-series-line-color-when-value-is-under-predefined-level/VB/Form1.vb#L24

vb
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler chartControl1.BoundDataChanged, AddressOf OnBoundDataChanged
    InitializeSeries()

See Also

Generate Series from a Data Source

How to: Individually Change the View Type of Automatically Created Series

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace