2017-05-30 64 views
1

我对饼图非常新,我有一个显示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); 
    } 
+0

也许你想显示用户名和时间的标签。所以用户名和时间一起加上前缀。 'chart1.Series [“Series1”]。Points [index] .Label = row [“User”]。ToString()+“:”+ string.Format(“{0:00}:{1:00}:{ 2:00}“,(总数/ 60)/ 60,(总数/ 60)%60,总数%60);' –

+0

这样做!感谢您的帮助! – Marcus

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