Smoothing a curve can be done by calculating what is called a moving average. Hereby, each value (data point) in the original data set is replaced by an average calculated from the value itself and its surrounding values.

An example function would be the following:

```
''' <summary>
''' Calculates the moving average with the given range over the given array and returns the result.
''' </summary>
''' <param name="arr">The array to use for calculation.</param>
''' <param name="Range">The number of previous and following values to average to the resulting value.</param>
Public Function CalcMovAvg(ByVal arr As Double(), ByVal Range As Byte) As Double()
'Create an array with the same size as the given one
Dim ret(UBound(arr)) As Double
'The indizes between which the values will be averaged; change with each iteration
Dim FromIndex, ToIndex As Integer
'Buffer for average calculation; changes with each iteration
Dim TempAvg As Double
'Iterate through every element in the given array
For i As Integer = 0 To UBound(arr)
'Set start and end indizes (keep array bounds in mind)
FromIndex = If(i < Range, 0, i - Range)
ToIndex = If((UBound(arr) - i) < Range, UBound(arr), i + Range)
'Clear buffer from previous calculations
TempAvg = 0
'Calculate the average from arr(FromIndex) to arr(ToIndex)
For j As Integer = FromIndex To ToIndex
TempAvg += arr(j) / (ToIndex + 1 - FromIndex)
Next
'Save average in resulting array
ret(i) = TempAvg
Next
'Return result
Return ret
End Function
```

If you, for example have a series of values like this:

arr = {3, 8, 1, 7, 4, 2}

and have Range set to 1, the function will calculate as follows:

ret(0) = (3 + 8) / 2

ret(1) = (3 + 8 + 1) / 3

ret(2) = (8 + 1 + 7) / 3

...

The higher the value of Range, the more values will be averaged, the smoother the resulting curve will be.

For your second problem of X values sometimes missing, I suppose the simplest solution would be to perform a linear interpolation that would look like this (treating 0-values as missing):

arr = {3, 8,

**0**,

**0**, 4, 2}

->

ret = {3, 8,

**6.666**,

**5.333**, 4, 2}

You take the existing values that are next to those that are missing (in the example, 8 and 4) and imagine a linear increase/decrease between them. Maybe somebody else can provide you some code for that.

Hope this helped.

[Edit - Changed the < and > in the code to "& l t;" (minus the spaces) and "& g t;" so the code block wouldn't think they were html tags and will format the code properly]