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
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/DevExpress-Resources/Demo-247.html
关键字: XtraCharts
评论列表
暂无评论
请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!
慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。
电话:400-700-1020
023-66090381
邮箱:sales@evget.com
相关资源
- DXCharts入门手册
- 将ChartControl添加到Windows窗体中
- DevExpress DXCharts入门手册
- jQuery为WebChartControl控件增加交互性
- XtraCharts入门教程一:利用向导创建ASP.NET图表
- Silverlight版本在线演示 Realtor World
- ASP.NET & MVC版本在线演示Webmail客户端
- WPF版本在线演示 Realtor World
- XtraCharts入门教程二:创建一个简单的非绑定图表
- XtraCharts入门教程三:绑定图表系列到数据源
- 利用滚动图例创建一个图表控件
- DXCharts图表控件来自定义图表标题
- XtraCharts入门教程四:使用Series模板自动创建Series
- 如何调用自定义约会表单中的ASPxPopupControl控件?
- 根据活动视图打印ASPxScheduler
- ASP.NET & MVC在线演示ASP.NET & MVC在线演示Touch Board
- XtraCharts示例一:向Windows窗体应用程序中添加图表
- XtraCharts示例二:向Web应用程序中添加图表
- XAF在线演示 - 桌面与Web的项目经理
- Money Monkey