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

时间:2017-04-29 23:31:45

标签: 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].[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;

1 个答案:

答案 0 :(得分:1)

试试这个:

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

enter image description here