2017-07-27 56 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