asp:图表堆积条形图奇怪的叠加

时间:2016-12-20 03:08:32

标签: c# aspchart

我有一个asp:我用c#填充的图表。见下文:

    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

这是确保所有系列点都有值(但仍然有重影数据条)后的输出:

https://www.dropbox.com/s/aan8ne7twmqd14f/Capture2.jpg?dl=0

0 个答案:

没有答案