2017-07-27 73 views
1

使用MS Chart的VB2010:我已經添加了一個系列作爲點圖。有時候會有超過1000分,點標籤變得太混亂了。我有智能標籤打開:在MS Chart for .NET中關閉點標籤

cht.Series("srs").SmartLabelStyle.Enabled = True 

但它仍然看起來不好。所以我添加了一個上下文菜單來關閉標籤。用戶然後可以放大到一個點,如果他們希望重新打開標籤。我似乎無法找到一種方法來做到這一點,而無需循環遍歷所有數據點。

我完全可以通過

cht.Series("srs").Enabled = False 

隱藏點和標籤,但我只想要的標籤被隱藏,然後再顯示當用戶選擇了它。

任何幫助表示讚賞。

編輯: 由於我還沒有找到一種方法來關閉標籤,並使用一個命令,我目前正在循環訪問系列中的每個點。

Me.Cursor = Cursors.WaitCursor 
    Application.DoEvents() 

    'suspend updating UI 
    cht.Series.SuspendUpdates() 

    'cycle through all points in the series and set the label either to an empty string or whatever is cached in the Tag property. 
    'todo: this is not efficient for large datasets but its the only thing we have. 
    For Each pt As DataPoint In cht.Series("srs").Points 
     If mnuDisplayLabels.Checked Then 
      pt.Label = pt.Tag.ToString 
     Else 
      pt.Label = "" 
     End If 
    Next pt 

    'resume updating UI 
    cht.Series.ResumeUpdates() 

    'force redraw of chart 
    cht.Update() 

回答

2

我認爲你必須循環,但是你想暫停更新用戶界面,直到你完成了所有的點。嘗試像這樣:

chart1.Series.SuspendUpdates(); 

foreach (Series s in chart1.Series) 
{ 
    s.IsValueShownAsLabel = false; 
} 

chart1.Series.ResumeUpdates(); 
+0

那麼這就是我害怕,但讓我給一個鏡頭。 – sinDizzy