C# ASP.NET图表自定义标签从总时间以秒为单位显示HH:MM:SS
我需要在图表中添加一个自定义标签,以在asp.net中显示HH:MM:SS来自sql server的时间以秒为单位,图表的填充方式如下:C# ASP.NET图表自定义标签从总时间以秒为单位显示HH:MM:SS,c#,asp.net,.net,charts,mschart,C#,Asp.net,.net,Charts,Mschart,我需要在图表中添加一个自定义标签,以在asp.net中显示HH:MM:SS来自sql server的时间以秒为单位,图表的填充方式如下: SqlConnection con = new SqlConnection(easystone); SqlDataAdapter graph = new SqlDataAdapter("SELECT [User], sum([Total Time]) as [total time] ,[week] FROM [Toolpaths].[dbo]
SqlConnection con = new SqlConnection(easystone);
SqlDataAdapter graph = new SqlDataAdapter("SELECT [User], sum([Total Time]) as [total time] ,[week] FROM [Toolpaths].[dbo].[totaltimeuser] where [week] like '" + DropDownList2.Text + "' group by [user], [week] order by 'total time' desc", con);
DataTable graphdata = new DataTable();
graph.Fill(graphdata);
chart1.DataSource = graphdata;
chart1.ChartAreas["ChartArea1"].AxisX.Title = "";
chart1.Series["Series1"].XValueMember = "User";
chart1.Series["Series1"].YValueMembers = "total time";
year.Text = DropDownList2.Text;
试试这个:
protected void Page_Load(object sender, EventArgs e)
{
foreach (DataRow row in graphdata.Rows)
{
int total = (int)row["total time"];
int index = chart1.Series[0].Points.AddXY(row["User"], new object[] { total });
chart1.Series[0].Points[index].Label = string.Format("{0:00}:{1:00}:{2:00}", (total / 60) / 60, (total / 60) % 60, total % 60);
}
}