C#:Form1.cs |
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace BindUsingTemplatesRuntimeCS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private DataTable CreateChartData() {
DataTable table = new DataTable("Table1");
table.Columns.Add("Month", typeof(String));
table.Columns.Add("Section", typeof(String));
table.Columns.Add("Value", typeof(Int32));
table.Rows.Add(new object[] { "Jan", "Section1", 10 });
table.Rows.Add(new object[] { "Jan", "Section2", 20 });
table.Rows.Add(new object[] { "Feb", "Section1", 20 });
table.Rows.Add(new object[] { "Feb", "Section2", 30 });
table.Rows.Add(new object[] { "March", "Section1", 15 });
table.Rows.Add(new object[] { "March", "Section2", 25 });
return table;
}
private void Form1_Load(object sender, EventArgs e) {
ChartControl chart = new ChartControl();
chart.DataSource = CreateChartData();
chart.SeriesDataMember = "Month";
chart.SeriesTemplate.ArgumentDataMember = "Section";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] {"Value"});
chart.SeriesTemplate.View = new StackedBarSeriesView();
chart.SeriesNameTemplate.BeginText = "Month: ";
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
}
}
|
VB:Form1.vb |
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace BindUsingTemplatesRuntimeCS
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Function CreateChartData() As DataTable
Dim table As New DataTable("Table1")
table.Columns.Add("Month", GetType(String))
table.Columns.Add("Section", GetType(String))
table.Columns.Add("Value", GetType(Int32))
table.Rows.Add(New Object() { "Jan", "Section1", 10 })
table.Rows.Add(New Object() { "Jan", "Section2", 20 })
table.Rows.Add(New Object() { "Feb", "Section1", 20 })
table.Rows.Add(New Object() { "Feb", "Section2", 30 })
table.Rows.Add(New Object() { "March", "Section1", 15 })
table.Rows.Add(New Object() { "March", "Section2", 25 })
Return table
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim chart As New ChartControl()
chart.DataSource = CreateChartData()
chart.SeriesDataMember = "Month"
chart.SeriesTemplate.ArgumentDataMember = "Section"
chart.SeriesTemplate.ValueDataMembers.AddRange(New String() {"Value"})
chart.SeriesTemplate.View = New StackedBarSeriesView()
chart.SeriesNameTemplate.BeginText = "Month: "
chart.Dock = DockStyle.Fill
Me.Controls.Add(chart)
End Sub
End Class
End Namespace
|