.net 叠层coulmn图中的多序列数据绑定

.net 叠层coulmn图中的多序列数据绑定,.net,stacked,.net,Stacked,当我在堆叠coulmn图表中使用多个系列绑定数据时,只有第一个系列是 用数据显示,其他系列不显示。我遍历系列并添加点 动态地进行系列化,但问题仍然存在。我还设置了isshowedaslabel 属性为真,但问题不解决,请帮助我 aspx代码: XValueMember=“qno”YValueMembers=“option3”> **.aspx.cs** assessdal d=新assessdal(); SqlConnection con=dbconnect.GetConnection();

当我在堆叠coulmn图表中使用多个系列绑定数据时,只有第一个系列是
用数据显示,其他系列不显示。我遍历系列并添加点 动态地进行系列化,但问题仍然存在。我还设置了isshowedaslabel
属性为真,但问题不解决,请帮助我

aspx代码:
XValueMember=“qno”YValueMembers=“option3”>
**.aspx.cs**
assessdal d=新assessdal();
SqlConnection con=dbconnect.GetConnection();
SqlCommand cmd=new SqlCommand(“选择assessid、qno、description、,
选项1、选项2、选项3、选项4来自评估测试”,con);
SqlDataReader reder=cmd.ExecuteReader();
Chart2.DataSource=d.showop1();
图2.DataBind();
图表2.系列[“系列1”]。IsValueShownAsLabel=true;
图表2.系列[“系列2”]。IsValueShownAsLabel=true;
图表2.系列[“系列3”]。IsValueShownAsLabel=true;
图表2.系列[“系列4”]。IsValueShownAsLabel=true;
while(reder.Read())
{
if(reder.HasRows)
{
//图表2.系列[“系列1”]点.数据绑定(reder,“选项3”);
//图表2.系列[“系列2”]点.数据绑定(reder,“选项3”);
//图表2.系列[“系列3”]点.数据绑定(reder,“选项3”);
//图表2.系列[“系列4”]点.数据绑定(reder,“选项3”);
}
foreach(图表2中的系列s.系列)
{
s、 点数。数据绑定(reder,“选项3”);
}
}

我建议使用DataBindCrossTable方法将数据绑定到堆叠条形图/堆叠柱形图。请看下面的示例:


该方法基本上对指定列执行GROUP BY操作,并为该列中的每个不同值创建一个图表系列。

示例@kad81引用已移动,但它没有处理图表类型。根据我的经验,DataBindCrossTable默认为柱状图

下面是示例中的相关代码片段,另外我在底部添加了循环以处理堆叠柱形图样式

// Setup the data
var dt = new System.Data.DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("BugCount", typeof(int));
dt.Columns.Add("Day", typeof(int));
dt.Rows.Add("Kim", 10, 0);
dt.Rows.Add("Kim", 12, 1);
dt.Rows.Add("Kim", 18, 2);
dt.Rows.Add("Kim", 5, 3);
dt.Rows.Add("Philby", 18, 0);
dt.Rows.Add("Philby", 25, 1);
dt.Rows.Add("Philby", 9, 2);
dt.Rows.Add("Philby", 32, 3);

// Build the chart
this.chart1.Series.Clear();
this.chart1.DataBindCrossTable(dt.Rows, "Name", "Day", "BugCount", "");

foreach (Series s in this.chart1.Series)
{
    s.ChartType=SeriesChartType.StackedColumn;
}
// Setup the data
var dt = new System.Data.DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("BugCount", typeof(int));
dt.Columns.Add("Day", typeof(int));
dt.Rows.Add("Kim", 10, 0);
dt.Rows.Add("Kim", 12, 1);
dt.Rows.Add("Kim", 18, 2);
dt.Rows.Add("Kim", 5, 3);
dt.Rows.Add("Philby", 18, 0);
dt.Rows.Add("Philby", 25, 1);
dt.Rows.Add("Philby", 9, 2);
dt.Rows.Add("Philby", 32, 3);

// Build the chart
this.chart1.Series.Clear();
this.chart1.DataBindCrossTable(dt.Rows, "Name", "Day", "BugCount", "");

foreach (Series s in this.chart1.Series)
{
    s.ChartType=SeriesChartType.StackedColumn;
}