Version

Creating Chart In Code Behind

Topic Overview

Purpose

This topic demonstrates, with code examples, how to create the UltraDataChart™ control in code-behind.

Required Background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides a general overview of the UltraDataChart control

This topic provides information on getting started with the UltraDataChart control.

This topic provides information on requirements of Series objects in the UltraDataChart control.

Overview

Preview

The following is the preview of the result of this topic.

DataChart Creating Chart In Code Behind 1.png

Application Requirements

  1. Install the Ultimate UI for Windows Forms 2014 Volume 2 or later version of the product.

  2. Start with new Windows Forms application using Visual Studio 2013-2017 or later version.

Required Assemblies.

  • Infragistics.Win.DataVisualization.Shared.

  • Infragistics.Win.DataVisualization.UltraDataChart.

  • Infragistics.Portable.Core.

Required Namespaces.

In C#:

using Infragistics.Win.DataVisualization;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

In Visual Basic:

Imports Infragistics.Win.DataVisualization
Imports System.Collections
Imports System.Drawing
Imports System.Windows.Forms

Chart Requirements

The chart control supports various types of data visualizations called Series. These series objects can visualize wide range of data source. Refer to the Series Types topic for complete list of series supported in the chart control. Each type of series can plot data that meets certain requirements (such as number of data column and their types) as well as what type of axis can be used with it. Refer to the Series Requirements topic for requirements for each of the series.

For demonstration purpose, this topic uses sample data with only one AreaSeries and two axes: CategoryXAxis and NumericYAxis.

Creating Data Source

Copy sample data code from the Sample Energy Data resource and create an instance of category sample data:

In C#:

var data = new EnergyProductionDataSample();

In Visual Basic:

Dim data As New EnergyProductionDataSample()

Creating Axes

The following code example defines the category X-axis for displaying labels on horizontal axis.

Note
Note:

The DataSource property is required in order to bind the category axis to IEnumerable data.

In C#:

var xAxis = new CategoryXAxis
            {
                Label = "Label",
                DataSource = data
            };

In Visual Basic:

Dim xAxis = New CategoryXAxis() With { _
      .Label = "Label", _
      .DataSource = data _
}

The following code example defines the numeric Y-axis for displaying value on vertical axis.

In C#:

var yAxis = new NumericYAxis();

In Visual Basic:

Dim yAxis = New NumericYAxis()

Creating Series

Create an instance of a series bounding to the data source and setting data mapping. In addition, the series must have settings for two axes created in the previous section.

In C#:

AreaSeries series = new AreaSeries();
series.XAxis = xAxis;
series.YAxis = yAxis;
series.ValueMemberPath = "Coal";
series.DataSource = data;

In Visual Basic:

Dim series = New AreaSeries()
series.DataSource = data
series.ValueMemberPath = "Coal"
series.XAxis = xAxis
series.YAxis = yAxis

Creating Chart

Create an instance of the chart control with one series and two axes.

In C#:

UltraDataChart chart = new UltraDataChart();
chart. Dock = DockStyle.Fill ;
chart.Axes.Add(xAxis);
chart.Axes.Add(yAxis);
chart.Series.Add(series);

In Visual Basic:

Dim chart As New UltraDataChart()
chart.Dock = DockStyle.Fill
chart.Axes.Add(xAxis)
chart.Axes.Add(yAxis)
chart.Series.Add(series)

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic provides information on getting started with the UltraDataChart control.

This topic provides information on requirements of Series objects in the UltraDataChart control.

This topic demonstrates creating WinForms UltraDataChart using the VisualStudio designer interface.