C# asp:图表堆叠条形图重叠
我有一个asp:图表,我正在使用c#填充它。见下文:C# asp:图表堆叠条形图重叠,c#,webforms,aspchart,C#,Webforms,Aspchart,我有一个asp:图表,我正在使用c#填充它。见下文: protected void populateBarChart() { int userDeptId = int.Parse(Session["userDept"].ToString()); DateTime? selectedDate = null; string query = "SELECT * FROM [dbo].sf_MonthEndChartDepartment(
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>
它就像我所期望的那样填充,除了一些数据系列是在其他堆叠条之上的“浮动”,还有那些奇怪的箭头状水平线的东西。见下文:
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
}
是否有人知道这些线是什么以及如何移除它们,是否有人知道为什么一些堆叠的钢筋是浮动的
这是jstreet提供帮助之前的输出:
这是确保所有系列点都有值(但仍有重影数据条)后的输出:
在堆叠条形图中,不能有“缺失”数据。如果某个特定点上某个特定序列的数据丢失,您必须显式地将其添加为0(零)值。一个漂亮的jstreet!我将对此进行检查并使用结果进行更新。@jstreet谢谢,并且有一个空结果为零值的结果集完美地修复了“浮动”条。我仍然能看到那些奇怪的标记,比如水平线。有什么想法吗?谢谢看,我怀疑你的图表中可能有“幽灵”系列。您的代码未显示创建序列的位置和方式。请阅读以下内容:。在堆叠条形图中,不能有“缺失”数据。如果某个特定点上某个特定序列的数据丢失,您必须显式地将其添加为0(零)值。一个漂亮的jstreet!我将对此进行检查并使用结果进行更新。@jstreet谢谢,并且有一个空结果为零值的结果集完美地修复了“浮动”条。我仍然能看到那些奇怪的标记,比如水平线。有什么想法吗?谢谢看,我怀疑你的图表中可能有“幽灵”系列。您的代码未显示创建序列的位置和方式。请阅读以下内容:。