2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

DevExpress XtraCharts示例二:向Web应用程序中添加图表

来源:本站原创   发布时间:2012-09-17   浏览:3794次

本示例主要介绍如何在设计时和运行时添加WebChartControl到web页面。

设计时

默认情况下, WebChartControl项目被添加到VS IDE下的DX.12.1: Data 工具箱选项卡。因此,若要Web Chart图表控件添加到您的项目中,你只需要拖动相应的工具箱项目,然后将其放置到窗体上。

DevExpress,XtraCharts,示例,ChartControl控件,图表,web页面

接下来,你可以在图表中添加2D和3D系列,并且用数据填充。

运行时

1、建一个新的ASP.NET Web应用程序(Visual Studio 2008或2010),或打开一个现有的ASP.NET Web应用程序。

2、切换到Default.aspx 页面的Design视图,将ASPxButton控件从DX.12.1: Common Controls工具箱选项卡中,拖动到页面。接下来,我们将处理Click事件,从而生成web图表。

DevExpress,XtraCharts,示例,ChartControl控件,图表,web页面

3、将所需的程序集添加到项目中。

4、双击ASPxButton1,处理Click事件。将如下的代码添加到事件处理器中。

C#
using System;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
// ... 
protected void ASPxButton1_Click(object sender, EventArgs e) {
// Create a WebChartControl instance. 
WebChartControl WebChartControl1 = new WebChartControl();
// Add the chart to the form. 
// Note that a chart isn't initialized until it's added to the form's collection of controls. 
this.form1.Controls.Add(WebChartControl1);
// Create a line series and add points to it. 
Series series1 = new Series("My Series", ViewType.Line);
series1.Points.Add(new SeriesPoint("A", new double[] { 2 }));
series1.Points.Add(new SeriesPoint("B", new double[] { 7 }));
series1.Points.Add(new SeriesPoint("C", new double[] { 5 }));
series1.Points.Add(new SeriesPoint("D", new double[] { 9 }));
// Add the series to the chart. 
WebChartControl1.Series.Add(series1);
}


VB
Imports System
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
' ... Protected Sub ASPxButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
' Create a WebChartControl instance. 
Dim WebChartControl1 As New WebChartControl()' Add the chart to the form. 
' Note that a chart isn't initialized until it's added to the form's collection of controls. 
Me.form1.Controls.Add(WebChartControl1)
' Create a line series and add points to it. 
Dim series1 As New Series("My Series", ViewType.Line)
series1.Points.Add(New SeriesPoint("A", New Double() { 2 }))
series1.Points.Add(New SeriesPoint("B", New Double() { 7 }))
series1.Points.Add(New SeriesPoint("C", New Double() { 5 }))
series1.Points.Add(New SeriesPoint("D", New Double() { 9 })) ' Add the series to the chart. 
WebChartControl1.Series.Add(series1)
End Sub 

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/344.html
扫码咨询
电话咨询
023-68661681
返回
顶部