B4J Question [xChartLite] Showing Many X Points Without Data

cklester

Well-Known Member
Licensed User
I'm showing data accumulated over several months. I would like to plot the lines with the X-axis containing all the days in-between two dates. However, not all day points will have actual data. I tried passing Null as the line data for those dates, but that didn't work.

Is there any way to show plot points between points with data?

e.g., the X-axis will be labeled 2022.01.01, 2022.01.02, 2022.01.03, 2022.01.04, 2022.01.05, 2022.01.06, etc... but I only have data points for 2022.01.01, 2022.01.04, and 2022.01.06. Is it possible to include those X-axis points that don't have data points associated with them?
 

klaus

Expert
Licensed User
Longtime User
I have done it in the xGraph class.
The missing values are replaced by a very big value, which the user can define.
When drawing, the program checks for each line if both points are below the missing value and draws the line.
To not penalize the drawing routine without missing values, I use two drawing routines one without missing values and one with.
It was easy to implement, but the task is a bit more complex for xChart due to the different chart types.
But you could add it in your module.

Below the drawing routine from the xGraph class, it draws several curves, their indexes are in a list lstCurvesToDisplay.
mGraphWithMissingData is a Boolean property.
mMissingDataValue is the missing data value property, equal to 100000000 by default.
B4X:
'Draws the selected Curves, internal routine
Private Sub DrawCurvesInternal
    Private c, nc, s, col, w As Int
    Private x0, y0, x1, y1 As Int
    Private pthCurves As B4XPath
   
    If lstCurvesToDisplay.Size = 0 Then
        Return
    End If
   
    pthCurves.Initialize(Graph.Left, Graph.Top)
    pthCurves.LineTo(Graph.Right, Graph.Top)
    pthCurves.LineTo(Graph.Right, Graph.Bottom)
    pthCurves.LineTo(Graph.Left, Graph.Bottom)
    pthCurves.LineTo(Graph.Left, Graph.Top)
   
    xcvsGraph.ClipPath(pthCurves)

    If mGraphWithMissingData = False Then
        For nc = 0 To lstCurvesToDisplay.Size - 1
            c = lstCurvesToDisplay.Get(nc)
            If mUseCustomColors = False Then
                col = CurveColor(nc)
                w = CurveWidth(nc)
            Else
                col = CurveCustomColor(c)
                w = CurveCustomWidth(c)
            End If
            x0 = Graph.Left
            y0 = Graph.Bottom - (CurveY(c, ScaleX.IBegin) - ScalesY(c).MinVal) * ScalesY(c).Scale
            For s = ScaleX.IBegin + 1 To ScaleX.IEnd
                x1 = Graph.Left + (CurveX(s) - CurveX(ScaleX.IBegin)) * ScaleX.Scale
                y1 = Graph.Bottom - (CurveY(c, s) - ScalesY(c).MinVal) * ScalesY(c).Scale
                xcvsGraph.DrawLine(x0, y0, x1, y1, col, w)
                x0 = x1
                y0 = y1
            Next
        Next
    Else
        For nc = 0 To lstCurvesToDisplay.Size - 1
            c = lstCurvesToDisplay.Get(nc)
            If mUseCustomColors = False Then
                col = CurveColor(nc)
                w = CurveWidth(nc)
            Else
                col = CurveCustomColor(c)
                w = CurveCustomWidth(c)
            End If
            x0 = Graph.Left
            y0 = Graph.Bottom - (CurveY(c, ScaleX.IBegin) - ScalesY(c).MinVal) * ScalesY(c).Scale
            For s = ScaleX.IBegin + 1 To ScaleX.IEnd
                x1 = Graph.Left + (CurveX(s) - CurveX(ScaleX.IBegin)) * ScaleX.Scale
                y1 = Graph.Bottom - (CurveY(c, s) - ScalesY(c).MinVal) * ScalesY(c).Scale
                If CurveY(c, s - 1) < mMissingDataValue And CurveY(c, s) < mMissingDataValue Then
                    xcvsGraph.DrawLine(x0, y0, x1, y1,col, w)
                End If
                x0 = x1
                y0 = y1
            Next
        Next
    End If
   
    xcvsGraph.Invalidate
    xcvsGraph.RemoveClip
End Sub
 
Upvote 1
Top