ASP.NET 图表自定义标签显示 HH:MM:SS 从总时间开始(以秒为单位)

ASP.NET Chart Custom Label Show HH:MM:SS From Total Time In Seconds

我需要在我的图表中添加一个自定义标签以在 asp.net 中显示 HH:MM:SS 来自 sql 服务器的时间以秒为单位并且图表正在按如下方式填充:

    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);
        }
    }