【问题标题】:How to create a gap (empty points) in the chart series如何在图表系列中创建间隙(空点)
【发布时间】:2016-08-21 08:53:38
【问题描述】:

我正在尝试使用 vb 图表绘制图表。缺少一些 X 值,我想在系列图中将其保留为空白。即,X 值从 0.695、0.7、0.705 等开始。但它们之间可能存在一些差距(例如:0.74、0.745、1.71、1.715),我希望将其作为差距(即 0.745 到 1.71)。

如果有帮助的话,我可以创建一个空点数组。下面是相同的代码。

Dim interval As Double = 0.0
Dim empty(0) As Double
Dim decimalpart As Integer = 0

    interval = freq1(1) - freq1(0)
    If interval.ToString().IndexOf(".") = -1 Then
        decimalpart = 0     'No decimal part                                     
    Else
        decimalpart = interval.ToString().Substring(interval.ToString().IndexOf(".") + 1).Length    'To find the number of decimal part
    End If
    y = 0
    For i As Integer = 0 To freq1.Length - 2    'Dont need to access the last data. It would be accessed in the previous loop
        If Math.Round((freq1(i + 1) - freq1(i)), decimalpart) > interval Then
            empty(y) = freq1(i) + interval
            y += 1
            ReDim Preserve empty(y)
            While (empty(y - 1) + interval < freq1(i + 1))
                empty(y) = empty(y - 1) + interval
                y += 1
                ReDim Preserve empty(y)
            End While
        End If
    Next
    ReDim Preserve empty(y - 1)

上面的代码查找区间并查看下一个值是否在区间范围内。否则它会发现使用间隔值增加的值。 freq1() 是包含 X 轴值的数组。但是,我不确定如何使用 empty() 删除 X 轴值。 (不确定,是否可以使用 Chart.Series().EmptyPointStyle)

【问题讨论】:

  • 你的目标不明确。您是否正在寻找一种从系列中删除“空”点的方法?还是您希望它们绘制为空(即显示一个间隙)?
  • 我想显示出现在图表系列图中的差距。

标签: vb.net visual-studio charts


【解决方案1】:

我想显示出现在图表系列图中的差距。

我不会假装您提供的代码在做什么,但是通过将DataPoint.IsEmpty 属性设置为True 来在折线图中显示空白点的间隙。

这是一个简单的例子。

Dim s As New Series
s.ChartType = SeriesChartType.FastLine
s.Color = Color.Black
s.BorderWidth = 2

' make some points
For x As Double = 0.5 To 4 Step 0.025
    Dim dp As New DataPoint(x, (2.0 * x + 3))

    ' apply some filtering criteria to set some points to empty
    If dp.XValue >= 1.2 AndAlso dp.XValue < 1.5 Then dp.IsEmpty = True
    If dp.XValue >= 3.1 AndAlso dp.XValue < 3.4 Then dp.IsEmpty = True

    s.Points.Add(dp)

Next

Chart1.Series.Clear()
Chart1.Legends.Clear()
Chart1.Series.Add(s)

您可以阅读有关此主题的更多信息:Using Empty Data Points in Chart Controls

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多