使用饼图添加用户名

时间:2017-05-30 23:58:21

标签: asp.net pie-chart

我对饼图很新,我有一个显示秒数hh:mm:ss但我还需要包含用户名,这里也是我的代码。

   string easystone = ConfigurationManager.ConnectionStrings["easystone"].ConnectionString;

    SqlConnection con = new SqlConnection(easystone);
    SqlDataAdapter graph = new SqlDataAdapter("SELECT[User] , sum(time) as [time] FROM avgtime3 group by[user]", con);
    DataTable graphdata = new DataTable();
    graph.Fill(graphdata);
    chart1.DataSource = graphdata;
    chart1.ChartAreas["ChartArea1"].AxisX.Title = "";
    foreach (DataRow row in graphdata.Rows)
    {
        int total = (int)row["time"];
        int index = chart1.Series["Series1"].Points.AddXY(row["User"], new object[] { total });
        chart1.Series["Series1"].Points[index].Label = // I need the username to go here.
        chart1.Series["Series1"].Points[index].Label = string.Format("{0:00}:{1:00}:{2:00}", (total / 60) / 60, (total / 60) % 60, total % 60);
    }

1 个答案:

答案 0 :(得分:1)

将用户名和时间一起加上前缀。

chart1.Series["Series1"].Points[index].Label = row["User"].ToString() + " : " + string.Format("{0:00}:{1:00}:{2:00}", (total / 60) / 60, (total / 60) % 60, total % 60);