我需要在我的图表中添加一个自定义标签以在 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].[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);
}
}
关于c# - ASP.NET 图表自定义标签显示 HH :MM:SS From Total Time In Seconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43701456/