here the code block that optimizes the graph automatically, it does not help for many small waveforms, but it works wonders on the 10k and larger ones:
Private Function Calculate3(ByVal aData()() As Double, ByVal AmplitudeUsed As Double, ByVal OffsetUsed As Double, ByVal LengthUsed As Integer) As Bitmap
Dim PS_Y As Double
'Instead of making this random, here a real calculation for the scale (chartheight / biggest waveform amplitude) :
PS_Y = 600 / (AmplitudeUsed * 2 + AmplitudeUsed * 0.1) ' Rnd() + 0.1
'Since our calculation method oscillates around zero with the same amplitude we can predict that we need the following offset:
Dim Origin As PointF = New PointF(0, 300)
Dim Data(), ST As Double
Dim lPoints As New List(Of PointF)
'set the x axis scale to make our waveform fit exactly:
Dim PS_X As Double = 900 / LengthUsed
Dim Img As New Bitmap(900, 600)
Dim ImgGR As Graphics = Graphics.FromImage(Img)
ImgGR.Clear(Color.White)
Dim WFPen As New Pen(Brushes.Black, 1)
'theese 2 values simply define an area in the picture where the waveforms are actually visible to not overlap with the axis / legend, set it to something that makes sense
Dim l As Integer = 20 'ChartRect.Left
Dim r As Integer = 700 'ChartRect.Right
Dim APT() As PointF
For i = 0 To aData.Length - 1
Dim iStart As Integer
Dim iEnd As Integer
Dim ScaleX As Double
Dim OrigX As Single
'Set sampletime to 1 second to keep the predefined scale from above, but still do the calculation as it would be needed with real data:
ST = 1 ' Rnd()
Data = aData(i)
If Data.Length = 0 Then Continue For
ScaleX = ST * PS_X
OrigX = Origin.X
iStart = (l - OrigX) / ScaleX
iEnd = (r - OrigX) / ScaleX
If iStart < 0 Then iStart = 0
If iEnd < 0 Then iEnd = 0
If iEnd > Data.Length - 1 Then iEnd = Data.Length - 1
If iStart > Data.Length - 1 Then iStart = Data.Length - 1
iStart = 0
iEnd = Data.Length - 1
If iEnd < iStart Then Continue For
If ScaleX < 0.3 Then 'more than 3 lines per point, summarize
Dim iPT As Integer
Dim FirstX As Integer
Dim LastX As Integer
Dim MinY As Single
Dim MaxY As Single
Dim tVal As Single
Dim iSt As Integer
Dim iEn As Integer
FirstX = Math.Truncate(iStart * ScaleX)
LastX = Math.Ceiling(iEnd * ScaleX)
ReDim APT((LastX - FirstX) * 2 - 1)
For iX = FirstX To LastX - 1
MinY = Single.MaxValue
MaxY = Single.MinValue
iSt = Math.Truncate(iX / ScaleX)
iEn = Math.Truncate((iX + 1) / ScaleX) - 1
If iSt < 0 Then iSt = 0
If iEn > Data.Length - 1 Then iEn = Data.Length - 1
For iDat = iSt To iEn
tVal = -Data(iDat) * PS_Y
If tVal > MaxY Then MaxY = tVal
If tVal < MinY Then MinY = tVal
Next
iPT = (iX - FirstX) * 2
APT(iPT) = Origin + New SizeF(iX, MinY)
APT(iPT + 1) = Origin + New SizeF(iX, MaxY)
Next
Else
ReDim APT(iEnd - iStart)
For j = iStart To iEnd
APT(j - iStart) = Origin + New SizeF(j * ScaleX, -(Data(j) * PS_Y))
Next
End If
ImgGR.DrawLines(WFPen, APT)
Next
Return Img
End Function
Thank you all for taking your time to read my question