【发布时间】:2017-07-28 21:15:01
【问题描述】:
VB2010 使用 MS 图表控件:我认为我的问题是基本的,但还没有找到如何去做。当窗体第一次加载图表控件时,什么都不显示,甚至没有网格。当我将点加载到我的系列中时,会显示网格和点。
如何显示仅包含网格线的模板图表,以便用户可以看到要填充的图表。我确实尝试将两个虚假点添加到我的一个系列中,然后禁用该系列以不显示这些点,但图表控件不认为这是渲染网格的原因。
感谢您的帮助。
编辑:感谢@baddack 让我深思。 这是我所做的:
在表单加载时创建一个虚假系列。该系列将在应用程序的整个生命周期中保留在图表中。
Dim srs As New Series 'create a new series
cht.Series.Add(srs) 'add series to chart
srs.ChartType = SeriesChartType.Point 'it will be a point chart with one point (or you can add several points to define your display envelope)
srs.Name = "bogus" 'name of our bogus series
srs.IsVisibleInLegend = False 'do not show the series in the legend
srs.Points.AddXY(25000, 1000) 'this will be a point in the upper-right corner of the envelope you want to display
srs.Points(0).MarkerColor = Color.Transparent 'no color for the marker
srs.Points(0).MarkerSize = 0 'no size for the marker
chtObstacles.Series("bogus").Enabled = True 'name of the bogus series
chtObstacles.Update() 'update the chart
那么当我运行我的进程时,我做的第一件事就是清除所有其他系列并启用虚假系列,以便可以使用它来调整“空”网格的大小。
cht.Series("srs1").Points.Clear()
cht.Series("srs2").Points.Clear()
cht.Series("bogus").Enabled = True
然后运行为图表提供点的进程:
if pointCount > 0 then
'turn off the series so it will not be used in the grid sizing
cht.Series("bogus").Enabled = False
'add points to the chart
'code to add points to MS Chart
endif
cht.ChartAreas("chaMain").RecalculateAxesScale() 'we must recalculate the axes scale to reset the mins/maxs
'resume updating UI
cht.Series.ResumeUpdates()
'force redraw of chart
cht.Update()
【问题讨论】: