DevExpress XtraCharts如何在Web页面中添加图表(运行示例)
1个回答
展开全部
实现此效果还有一个方法,请参阅:DevExpress XtraCharts ASPxCallbackPanel回调时如何添加图表(运行示例)。 下面将为你演示如何实现图表的添加。 1、创建一个新的ASP.NET Web应用程序(Visual Studio 2008或2010),或打开一个现有的。 2、切换到Default.aspx页面的设计视图,从DX.11.2:公共控件工具栏拖放一个ASPxButton到页面中。处理它的Click事件,生成一个Web图表。 3、将所需的程序集添加到项目中。 注意:如果你喜欢,控件也可以自动添加(拖放一个WebChartControl实例到页面中),这会影响你的web应用程序的Web.config文件。关于这些变化的更多信息,请参阅为DevExpress XtraCharts添加一个Web图表。4、现在,双击ASPxButton1,处理它的Click事件。将下面的代码添加到事件处理程序中。 注意:获取元素和动态创建WebChartControl的属性之前,应先添加Page.Form.Controls程序集。
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 运行Web应用程序,单击ASPxButton1看图表效果。
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 运行Web应用程序,单击ASPxButton1看图表效果。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询