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

如何在DevExpress ASPxGridView的DetailRow中显示图表?

来源:本站   发布时间:2012-03-01   浏览:2596次

要实现该功能,需在ASPxGridView.Templates.DetailRow 模板中添加一个图表.然后在后台代码中, 为图表添加数据(Init()方法中).WebChartControl.NamingContainer属性用于获取GridViewDetailRowTemplateContainer 及其KeyValue ,并相应的过滤图表数据。

关键代码:

[ASPX]

<Templates>

     <DetailRow>

         <dxchartsui:WebChartControl ID="WebChartControl1" runat="server" Height="400px"Width="530px" OnInit="WebChartControl1_Init">

          </dxchartsui:WebChartControl>

    </DetailRow>

 </Templates>

 

[C#]

protected voidWebChartControl1_Init(object sender, EventArgs e)

    {

        WebChartControl chart = (WebChartControl)sender;

        GridViewDetailRowTemplateContainer container =chart.NamingContainer as GridViewDetailRowTemplateContainer;

        int categoryId = Convert.ToInt32(container.KeyValue);

        string categoryName =ASPxGridView1.GetRowValuesByKeyValue(categoryId, newstring[] { "CategoryName"}).ToString();

        Series series = newSeries(categoryName, ViewType.Bar);

 

       series.ArgumentDataMember = "ProductName";

       series.ValueDataMembers.AddRange(new string[] { "UnitPrice"});

       chart.Series.Add(series);

        ((XYDiagram)chart.Diagram).AxisX.Label.Angle = 90;

       Session["CategoryID"] =categoryId;

       chart.DataSource = detailDataSource.Select(DataSourceSelectArguments.Empty);

       chart.DataBind();

    }

点击下载示例

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