首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示模板MS图表,NET

显示模板MS图表,NET
EN

Stack Overflow用户
提问于 2017-07-29 05:15:01
回答 1查看 60关注 0票数 0

VB2010使用MS图表控件:我想我的问题很基本,但还没有找到如何做的方法。当窗体第一次加载时,图表控件不显示任何内容,甚至不显示网格。当我将点加载到我的序列中时,网格加上这些点就会显示出来。

如何显示仅包含网格线的模板图表,以便用户可以看到要填充的图表。我确实尝试将两个伪点添加到我的一个系列中,然后禁用该系列以不显示这些点,但Chart控件不会将其视为呈现网格的理由。

谢谢你的帮助。

编辑:感谢@baddack给了我思考的食粮。下面是我所做的:

在表单加载时,创建一个伪造的系列。这一系列将在应用程序的生命周期中保留在图表中。

代码语言:javascript
复制
        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

然后,当我运行我的进程时,我做的第一件事是清除所有其他序列,并启用伪序列,以便它可以用来调整“空”网格的大小。

代码语言:javascript
复制
        cht.Series("srs1").Points.Clear()
        cht.Series("srs2").Points.Clear()
        cht.Series("bogus").Enabled = True

然后运行为图表提供点的流程:

代码语言:javascript
复制
  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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-29 05:57:56

您可以向图表中添加一个空点。这将使网格显示,但不显示任何点。

代码语言:javascript
复制
private void Form1_Load(object sender, EventArgs e)
{
    chart1.Series.Clear();
    SetChartAxisLines(chart1.ChartAreas[0]);

    Series s = new Series();
    chart1.Series.Add(s);
    s.Points.Add();
    s.Points[0].IsEmpty = true;
}

private void SetChartAxisLines(ChartArea ca)
{
    //X-Axis
    ca.AxisX.MajorGrid.LineColor = Color.DarkGray;
    ca.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
    ca.AxisX.MinorGrid.Enabled = true;
    ca.AxisX.MinorGrid.LineColor = System.Drawing.Color.Silver;
    ca.AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;

    //Y-Axis
    ca.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
    ca.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
    ca.AxisY.MinorGrid.Enabled = true;
    ca.AxisY.MinorGrid.LineColor = System.Drawing.Color.Silver;
    ca.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45382522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档