2017-05-30 21 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);