0
當我繪製條形圖時,某些項目在X軸上沒有正確繪圖,而等價的Y軸很好。.NET條形圖不能正確繪圖
我的用戶控制具有以下代碼,
<asp:Chart ID="Chart1" runat="server" Width="850px" Height="600px">
<Series>
<asp:series Name="Series1"></asp:series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
代碼來填充數據表,
protected DataTable GetGroupExperienceData(PickerEntity pickerEntity)
{
DataTable table;
table = new DataTable();
table.Columns.Add("Participant", typeof(string));
table.Columns.Add("Experience", typeof(Int32));
table.Columns.Add("Question", typeof(string));
DataRow row;
if (collListItems2.Count > 0 && collListItems2 != null)
{
for (int i = 0; i < collListItems2.Count; i++)
{
row = table.NewRow();
row["Participant"] = user.Name;
SPFieldLookupValue lpkFieldQName = new SPFieldLookupValue(itemRep["SurveyQuestion"].ToString());
string lkpQNameVal = lpkFieldQName.LookupValue;
row["Question"] = lkpQNameVal;
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("(Error)", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ">" + row["Question"].ToString(), "");
if (itemRep["Experience"] !=null)
{
row["Experience"] = itemRep["Experience"];
}
else
{
row["Experience"] = Convert.ToInt32("0");
}
table.Rows.Add(row);
}
}
return dt;
}
最後圖表繪製代碼,
protected void DrawExperienceChart(DataTable dt)
{
Chart1.Series["Series1"].ChartType = SeriesChartType.Bar;
Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.Series["Series1"].IsValueShownAsLabel = true;
Chart1.DataSource = dt;
Chart1.Series["Series1"].XValueMember = "Question";
Chart1.Series["Series1"].YValueMembers = "Experience";
Chart1.DataBind();
}
所有這些功能是由按鈕調點擊,
protected void btnGetReport_Click(object sender, EventArgs e)
{
DataTable dt = GetGroupExperienceData(pickerEntity);
DrawExperienceChart(dt);
}
這裏是輸出結果,在X軸上有很多「問題」數據缺失,但是相同的「體驗」在Y軸上很好地繪製。
我想可能是數據不進入數據表,但數據表有哪些我可以看到使用SPDiagnosticsService.Local.WriteTrace()
數據,