原創|其它|編輯:郝浩|2012-05-21 01:27:42.000|閱讀 611 次
概述:本示例演示了在Web頁面中如何通過點擊按鈕生成并顯示圖表。實現此效果還有一個方法。首先需要創建一個新的ASP.NET Web應用程序(Visual Studio 2008或2010),或打開一個現有的。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本示例演示了DevExpress XtraCharts開發中,在Web頁面中如何通過點擊按鈕生成并顯示圖表。實現此效果還有一個方法,請參閱:。
下面將為你演示如何實現圖表的添加。
1、創建一個新的ASP.NET Web應用程序(Visual Studio 2008或2010),或打開一個現有的。
2、切換到Default.aspx頁面的設計視圖,從DX.11.2:公共控件工具欄拖放一個ASPxButton到頁面中。處理它的Click事件,生成一個Web圖表。
3、將所需的程序集添加到項目中。
注意:如果你喜歡,控件也可以自動添加(拖放一個WebChartControl實例到頁面中),這會影響你的web應用程序的Web.config文件。關于這些變化的更多信息,請參閱。
4、現在,雙擊ASPxButton1,處理它的Click事件。將下面的代碼添加到事件處理程序中。
注意:獲取元素和動態創建WebChartControl的屬性之前,應先添加Page.Form.Controls程序集。
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
運行Web應用程序,單擊ASPxButton1看圖表效果。