我正在尝试从数据库中填充条形图,并希望添加一个带状线作为目标。我正在尝试在hh:mm:ss中添加值作为标签,但是当我尝试执行此操作时,它会重复这些值,并且得到的条数是我应有的两倍。
这是用于添加标签的代码,似乎在复制条形图:
foreach (DataRow row in dt.Rows)
{
int total = (int)row["Dialer_Time"];
int index = chtDialerTime.Series["Default"].Points.AddXY(row["agent_name"], new object[] { total });
chtDialerTime.Series["Default"].Points[index].Label = hhh_mm_ss(total);
}
所有代码:
protected void BindChart()
{
DataTable dt = new DataTable();
string query = string.Format("SELECT[agent_name], [Dialer Time] AS Dialer_Time FROM[vwDialerTimeToday] WHERE([Dialer Time] > 0) ORDER BY[Dialer Time] ");
dt = GetData(query);
chtDialerTime.DataSource = dt;
chtDialerTime.Series["Default"].XValueMember = "agent_name";
chtDialerTime.Series["Default"].YValueMembers = "Dialer_Time";
chtDialerTime.ChartAreas[0].AxisY.Maximum = 18000;
chtDialerTime.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chtDialerTime.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chtDialerTime.DataBind();
foreach (DataRow row in dt.Rows)
{
int total = (int)row["Dialer_Time"];
int index = chtDialerTime.Series["Default"].Points.AddXY(row["agent_name"], new object[] { total });
chtDialerTime.Series["Default"].Points[index].Label = hhh_mm_ss(total);
}
StripLine stripLine1 = new StripLine();
stripLine1.StripWidth = 0;
stripLine1.BorderColor = System.Drawing.Color.Green;
stripLine1.BorderWidth = 5;
stripLine1.BorderDashStyle = ChartDashStyle.DashDot;
stripLine1.IntervalOffset = 12600;
stripLine1.BackColor = System.Drawing.Color.Green;
chtDialerTime.ChartAreas[0].AxisY.StripLines.Add(stripLine1);
chtDialerTime.ChartAreas[0].AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 0.1F);
chtDialerTime.Series[0].Font = new Font("Arial", 18, FontStyle.Bold);
}
string hhh_mm_ss(int seconds)
{
int sec = seconds % 60;
int min = ((seconds - sec) / 60) % 60;
int hhh = (seconds - sec - 60 * min) / 3600;
return hhh > 0 ? string.Format("{2}:{1:00}:{0:00}", sec, min, hhh)
: min + ":" + sec.ToString("00");
}