vb.net - 带渐近线的 VB 图表
问题描述
到目前为止,我已经创建了一个功能正常的余弦和正弦图,但是 tan 不起作用,因为它依赖于渐近线,我不太确定如何使用 VB 使用图表,因为图表将每个点输出为连接为一行而不是单独的行。如果有人对此有任何经验,我将不胜感激,因为我在网上找不到任何可以进一步帮助我的东西。
For x As Integer = n To v Step 1
Dim y As Single
y = Math.Tan(x / 57.3)
'57.3 is an approximation for pi/180
Chart1.Series("plot4").Points.AddXY(x, y)
Next
End Sub
解决方案
如果您可以检测到不连续性,则可以添加一个将.IsEmpty属性设置为 True 的数据点。该点不会被绘制,在图中给出一个中断:
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Sub DrawGraph()
Chart1.Series.Clear()
Dim pts As New Series("tan") With {.ChartType = SeriesChartType.Line}
Dim nPoints = 541
Dim xMin = 0.0
Dim xMax = Math.PI * 3
Dim xInc = (xMax - xMin) / nPoints
For i = 0 To nPoints - 1
Dim x = xMin + i * xInc
Dim y = Math.Tan(x)
If i > 0 Then
' Check if the sign of y has changed and its value is large enough to suggest a discontinuity
If Math.Sign(pts.Points(i - 1).YValues(0)) = -Math.Sign(y) AndAlso Math.Abs(y) > 10 Then
pts.Points.Add(New DataPoint(x - xInc / 2, 0) With {.IsEmpty = True})
End If
End If
pts.Points.AddXY(x, y)
Next
Chart1.Series.Add(pts)
Chart1.ChartAreas(0).AxisY.Minimum = -50
Chart1.ChartAreas(0).AxisY.Maximum = 50
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DrawGraph()
End Sub
End Class
给出这样的东西:
(请原谅这张图表的粗俗。我没有时间很好地缩放它或给它上色。)
参考灵感:c# chart non Continuous。
推荐阅读
- amazon-web-services - 用户组的 DynamoDB 表结构
- python - Python - 使用变量导入模块
- facebook - Facebook WebGL 广告网络统一
- javascript - 如何过滤ag-grid中的行数据
- apiblueprint - 在 API-Blueprint 中参数化数据结构
- android - 如何从全文中查找特定单词并使其超链接可使用 textview 单击?
- angular - Angular 6 中的剑道网格:isEditing:如何?
- php - 通过 curl 将数据发布到 api
- python-2.7 - 如何使用 python 和 rest API 调用将动态 VHD 上传到 Azure?
- scala - 数组列的火花聚合