DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 示例代码 » DevExpress XtraCharts示例三:运行时绑定单个图表系列到外部数据源

DevExpress XtraCharts示例三:运行时绑定单个图表系列到外部数据源

作者:zhuhm   来源:本站原创   浏览:Loading...次   发布时间:2012-09-18   评论:0条

本示例主要演示了如何在运行时通过绑定单个系列到特定的数据源,从而实现将图表绑定到数据中。

C#:Form1.cs
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
namespace BindIndividualSeriesRuntimeCS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private DataTable CreateChartData(int rowCount) {
// Create an empty table.
DataTable table = new DataTable("Table1");
// Add two columns to the table.
table.Columns.Add("Argument", typeof(Int32));
table.Columns.Add("Value", typeof(Int32));
// Add data rows to the table.
Random rnd = new Random();
DataRow row = null;
for (int i = 0; i < rowCount; i++) {
row = table.NewRow();
row["Argument"] = i;
row["Value"] = rnd.Next(100);
table.Rows.Add(row);
}
return table;
}
private void Form1_Load(object sender, EventArgs e) {
// Create a chart.
ChartControl chart = new ChartControl();
// Create an empty Bar series and add it to the chart.
Series series = new Series("Series1", ViewType.Bar);
chart.Series.Add(series);
// Generate a data table and bind the series to it.
series.DataSource = CreateChartData(50);
// Specify data members to bind the series.
series.ArgumentScaleType = ScaleType.Numerical;
series.ArgumentDataMember = "Argument";
series.ValueScaleType = ScaleType.Numerical;
series.ValueDataMembers.AddRange(new string[] { "Value" });
// Set some properties to get a nice-looking chart.
((SideBySideBarSeriesView)series.View).ColorEach = true;
((XYDiagram)chart.Diagram).AxisY.Visible = false;
chart.Legend.Visible = false;
// Dock the chart into its parent and add it to the current form.
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
}
}


VB:Form1.vb
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Public Class Form1
Private Function CreateChartData(ByVal rowCount As Integer) As DataTable
' Create an empty table.
Dim Table As New DataTable("Table1") ' Add two columns to the table.
Table.Columns.Add("Argument", GetType(Int32))
Table.Columns.Add("Value", GetType(Int32))
' Add data rows to the table.
Dim Rnd As New Random()
Dim Row As DataRow = Nothing
Dim i As Integer
For i = 0 To rowCount - 1
Row = Table.NewRow()
Row("Argument") = i
Row("Value") = Rnd.Next(100)
Table.Rows.Add(Row)
Next i
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()
' Create an empty Bar series and add it to the chart.
Dim Series As New Series("Series1", ViewType.Bar)
Chart.Series.Add(Series)
' Generate a data table and bind the series to it.
Series.DataSource = CreateChartData(50)
' Specify data members to bind the series.
Series.ArgumentScaleType = ScaleType.Numerical
Series.ArgumentDataMember = "Argument"
Series.ValueScaleType = ScaleType.Numerical
Series.ValueDataMembers.AddRange(New String() {"Value"})
' Set some properties to get a nice-looking chart.
CType(Series.View, SideBySideBarSeriesView).ColorEach = True
CType(Chart.Diagram, XYDiagram).AxisY.Visible = False
Chart.Legend.Visible = False
' Dock the chart into its parent and add it to the current form.
Chart.Dock = DockStyle.Fill
Me.Controls.Add(Chart)
End Sub
End Class

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/DevExpress-Resources/Demo-247.html

关键字: XtraCharts 

相关产品: DXperience ASP.NET Subscription

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道