A newer version of this page is available. Switch to the current version.

ChartControl Class

Visualizes data as bars, areas, lines and other shapes. See Chart Control.

Namespace: DevExpress.XtraCharts

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

Declaration

[ToolboxBitmap(typeof(XtraChartsUIResFinder), "Bitmaps256.ChartControl.bmp")]
[Docking(DockingBehavior.Ask)]
[SerializationContext(typeof(ChartSerializationContext))]
public class ChartControl :
    Control,
    IChartContainer,
    ISupportBarsInteraction,
    IServiceProvider,
    ICommandAwareControl<ChartCommandId>,
    IChartRenderProvider,
    IChartDataProvider,
    IChartEventsProvider,
    IChartInteractionProvider,
    IPrintable,
    IBasePrintable,
    IChartAnimationProvider,
    ISupportInitialize,
    ICloneable,
    ICoreReference,
    IGestureClient,
    IToolTipControlClient,
    IRangeControlClientExtension,
    IRangeControlClient,
    ISupportLookAndFeel,
    IAnyControlEdit,
    ICustomBindingPropertiesProvider,
    IFilteringUIClient,
    IFilterCriteriaBindingAware,
    IDirectXClient,
    IXtraSerializable
<ToolboxBitmap(GetType(XtraChartsUIResFinder), "Bitmaps256.ChartControl.bmp")>
<Docking(DockingBehavior.Ask)>
<SerializationContext(GetType(ChartSerializationContext))>
Public Class ChartControl
    Inherits Control
    Implements IChartContainer,
               ISupportBarsInteraction,
               IServiceProvider,
               ICommandAwareControl(Of ChartCommandId),
               IChartRenderProvider,
               IChartDataProvider,
               IChartEventsProvider,
               IChartInteractionProvider,
               IPrintable,
               IBasePrintable,
               IChartAnimationProvider,
               ISupportInitialize,
               ICloneable,
               ICoreReference,
               IGestureClient,
               IToolTipControlClient,
               IRangeControlClientExtension,
               IRangeControlClient,
               ISupportLookAndFeel,
               IAnyControlEdit,
               ICustomBindingPropertiesProvider,
               IFilteringUIClient,
               IFilterCriteriaBindingAware,
               IDirectXClient,
               IXtraSerializable

Related API Members

The following members accept/return ChartControl objects:

Library Related API Members
Dashboard DashboardItemControlEventArgs.ChartControl
eXpressApp Framework ChartListEditor.ChartControl
PivotGridListEditor.ChartControl

Remarks

The ChartControl class is a visual control used to display assorted data graphically. It visualizes the Series of Points using one of the available View Types. The currently used View Type is accessed via the SeriesBase.View property. Note that at the same time, a chart can draw multiple series using different View Types.

ChartControl_Promo

A chart control contains multiple visual elements (diagram, axes, titles, labels, strips, constant lines, etc.), these aren't a Component, but can be selected at design time. Note that when any of these elements are selected, the Properties Window in the IDE is filtered and shows only the properties which correspond to the selected item. To enable these elements to be selected at runtime, set the ChartControl.RuntimeSelection property to true.

The ChartControl allows not only series data to be visualized on screen, but also to print and export it to various data formats (PDF, HTML, BMP, etc.). Note that export to image (called via ChartControl.ExportToImage method) is implemented internally in XtraCharts, and to enable other export formats, the XtraPrinting Library should be used. The XtraPrinting Library is not shipped with XtraCharts and should be installed separately. To check if the required XtraPrinting assemblies are available, use the ChartControl.IsPrintingAvailable method.

There are two possible ways to provide data for visualization within the ChartControl. You can either bind each series separately or the entire chart to data. Note that in both cases, you first need to create a data source (any object which implements either IList, IListSource or IBindingList interfaces), and then assign it to the ChartControl.DataSource property. If you want the DataSource to be automatically filled by the ChartControl at design and runtime, you need to specify its ChartControl.DataAdapter property, otherwise you will need to manually populate the datasource

Then, do one of the following:

NOTE

The ChartControl control is intended to be used in Windows® Forms applications only. If you need to add charting ability to your ASP. NET application, use the WebChartControl instead.

Examples

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);
        }

    }
}
See Also