Skip to content

Latest commit

 

History

History
257 lines (179 loc) · 6 KB

datachart-creating-chart-in-code-behind-winforms.adoc

File metadata and controls

257 lines (179 loc) · 6 KB

Creating Chart In Code Behind

Topic Overview

Purpose

This topic demonstrates, with code examples, how to create the {DataChartName}™ 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 {DataChartName} control

This topic provides information on getting started with the {DataChartName} control.

This topic provides information on requirements of Series objects in the {DataChartName} control.

Overview

Preview

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

DataChart Creating Chart In Code Behind 1

Application Requirements

  1. Install the Infragistics WinForms 2014 Volume 2 or later version of the product.

  2. Start with new Windows Forms application using {PlatformIDE} or later version.

Required Assemblies.

  • {ApiPlatform}Win.DataVisualization.Shared.{ApiVersion}

  • {ApiPlatform}Win.DataVisualization.UltraDataChart.{ApiVersion}

  • {ApiPlatform}Portable.Core.{ApiVersion}

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#:

CategorySampleData 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 {DataChartName} control.

This topic provides information on requirements of Series objects in the {DataChartName} control.

This topic demonstrates creating WinForms {DataChartName} using the VisualStudio designer interface.