我有一个使用 c# 填充的 asp:Chart。见下文:
protected void populateBarChart()
{
int userDeptId = int.Parse(Session["userDept"].ToString());
DateTime? selectedDate = null;
string query = "SELECT * FROM [dbo].sf_MonthEndChartDepartment(null , " + userDeptId + ") order by xAxisValue";
if (Session["selectedMonth"] != null)
{
selectedDate = DateTime.Parse(Session["selectedMonth"].ToString());
string sqlFormattedDate = ((DateTime)selectedDate).ToString("yyyy-MM-dd HH:mm:ss.fff");
query = "SELECT * FROM [dbo].sf_MonthEndChartDepartment('" + sqlFormattedDate + "' , " + userDeptId + ") order by xAxisValue";
}
if (cn.State != ConnectionState.Open)
cn.Open();
cmd = new SqlCommand(query, cn);
try
{
SqlDataReader dreader = cmd.ExecuteReader();
while (dreader.Read())
{
int projectTypId = Int32.Parse(dreader["ProjectTypeId"].ToString());
string xAxisValueMon = dreader["xAxisValueMon"].ToString();
double xAxisValue = double.Parse(dreader["xAxisValue"].ToString());
double yAxisValue = double.Parse(dreader["yAxisValue"].ToString());
// NOTE: Series are zero based, where database records are 1 based.
// Therefore subtract 1 from the projectTypeId to get correct series
if (projectTypId == CodHelpus.PROJECT_TYPE_SAVING)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "Cost Saving";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_REVENUE)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "Revenue (OZ)";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_RISK)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "Risk";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_LTO)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "LTO";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_SAFETY)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "Safety";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_CAPITAL)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "Capital";
}
else if (projectTypId == CodHelpus.PROJECT_TYPE_NA)
{
chart1.Series[projectTypId - 1].Points.Add(new DataPoint(xAxisValue, yAxisValue));
chart1.Series[projectTypId - 1].Label = "N/A";
}
}
foreach (Series cs in chart1.Series)
cs.ChartType = SeriesChartType.StackedColumn;
}
catch (SqlException ex)
{
}
finally
{
cmd.Dispose();
cn.Close();
}
//chart1.SaveXml(@"C:\NetworkDatatest\chart.xml"); //test the output
}
这是asp代码:
<div class="col-lg-6 nopadding">
<asp:Chart ID="chart1" runat="server" Width="500px" RightToLeft="No">
<Series>
<asp:Series ChartArea="ChartArea1" Name="Saving" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="Revenue" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="Risk" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="LTO" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="Safety" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="Capital" LabelForeColor="Transparent" Legend="Legend1" />
<asp:Series ChartArea="ChartArea1" Name="NA" LabelForeColor="Transparent" Legend="Legend1" />
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
<legends>
<asp:Legend Name="Legend1" Docking="Bottom">
</asp:Legend>
</legends>
</asp:Chart>
</div>
这是查询返回的结果的链接:
https://www.dropbox.com/s/iqdih3ae6iu5s0h/dataset_results.csv?dl=0
它按照我的预期填充,除了一些数据系列是其他堆叠条上方的“浮动”,还有那些奇怪的箭头状水平线的东西。见下文:
有谁知道这些线是什么以及如何删除它们,有谁知道为什么一些堆叠的条是漂浮物?
这是 jstreet 帮助之前的输出:
https://www.dropbox.com/s/ijmbf93sb1tf6f4/Capture.jpg?dl=0
这是确保所有系列点都有值之后的输出(但仍然有幽灵数据条):