要实现该功能,需在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