I have an asp:Chart that I'm populating using c#. See below:
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
}
Here is the asp code:
<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>
Here's a link to the results returned by the query:
https://www.dropbox.com/s/iqdih3ae6iu5s0h/dataset_results.csv?dl=0
It populates as I would expect, except some of the data series are "floaters" above the other stacked bars, and there's those weird arrow-like horizontal line things. See below:
Does anyone know what those lines are and how to remove them, and does anyone know why some of the stacked bars are floaters?
This is what the output looked like before help from jstreet:
https://www.dropbox.com/s/ijmbf93sb1tf6f4/Capture.jpg?dl=0
And this is the output after ensuring that there are values for all series points (but still has the ghost data bars):