Pre loader

Extend latest value of line chart to right of view port

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Hi,

My step line chart represents a real-time time series and the viewport slides forwards in realtime to show the last 5 minutes. Sometimes the value of the series doesn’t change for some seconds or minutes. This leaves a gap in the line chart between the latest value and the right side of the viewport (now).

I would like the latest value to always be extended as a horizontal line to meet the right side of the viewport.

I have half achieved this by extending FastLineRenderableSeries like so:

public class ExtendRightFastLineRenderableSeries : FastLineRenderableSeries
{
    protected override void InternalDraw(IRenderContext2D renderContext, IRenderPassData renderPassData)
    {
        base.InternalDraw(renderContext, renderPassData);

        var points = renderPassData.PointSeries;

        var yLast = renderPassData.YCoordinateCalculator.GetCoordinate(points.YValues.Last());

        var xLast = renderPassData.XCoordinateCalculator.GetCoordinate(points.XValues.Last());
        var xEnd = renderContext.ViewportSize.Width;

        using (var linePen = renderContext.CreatePen(this.SeriesColor, this.AntiAliasing, this.StrokeThickness))
        {
            using (var lineDrawingContext = renderContext.BeginLine(linePen, xLast, yLast))
            {
                lineDrawingContext.MoveTo(xEnd, yLast);
            }
        }
    }
}

The only problem is that when no data points are in the viewport (because the value last changed more than 5 minutes ago) then the Draw method of the FastLineRenderableSeries never gets called.

How can I force the redraw even though there are no points in the viewport. Alternatively, is there a better way to approach this?

Cheers
Felix

  • You must to post comments
2
0

Hi Andrew,

Thanks for the quick response. Your solution works perfectly. In case it helps others, here’s the full code:

public class ExtendRightFastLineRenderableSeries : FastLineRenderableSeries
{
    private double yLast;

    protected override void InternalDraw(IRenderContext2D renderContext, IRenderPassData renderPassData)
    {
        var xEnd = renderContext.ViewportSize.Width;
        var xLast = 0d;

        if (base.GetIsValidForDrawing())
        {
            base.InternalDraw(renderContext, renderPassData);

            var points = renderPassData.PointSeries;

            yLast = renderPassData.YCoordinateCalculator.GetCoordinate(points.YValues.Last());
            xLast = renderPassData.XCoordinateCalculator.GetCoordinate(points.XValues.Last());                
        }

        using (var linePen = renderContext.CreatePen(this.SeriesColor, this.AntiAliasing, this.StrokeThickness))
        {
            using (var lineDrawingContext = renderContext.BeginLine(linePen, xLast, yLast))
            {
                lineDrawingContext.MoveTo(xEnd, yLast);
            }
        }
    }

    protected override bool GetIsValidForDrawing()
    {
        return true;
    }
}
  • You must to post comments
0
0

Hi Felix,

Unfortunately, at the moment, SciChart will completely skip drawing of RenderableSeries if there are no points in the viewport.

I did inspect the code however and I did find this method in BaseRenderableSeries which is called to determine if the series is valid.

    /// <summary>
    /// Gets a value indicating whether this <see cref="BaseRenderableSeries"/> is valid for drawing.
    /// </summary>
    protected virtual bool GetIsValidForDrawing()
    {
        var isValid = (DataSeries != null &&
                       DataSeries.HasValues &&
                       IsVisible &&
                       CurrentRenderPassData != null &&
                       CurrentRenderPassData.PointSeries != null);

        return isValid;
    }

Do you want to try overriding that and returning true? It might force the series to draw at all times.

But, something else you want to do is ensure the base.InternalDraw is not called if the base.GetIsValidForDrawing() method returns false.

Best regards,

Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies