Pre loader

Custom FastErrorBarsRenderableSeries

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

0
0

Hi, I’m trying to create an effect similar to the FastErrorBarsRenderableSeries, but I only want to render the horizontal min & max lines, and not the vertical line. Can you suggest a way to achieve this?

  • You must to post comments
0
0

I don’t know if there is a more elegant approach but I’ve come up with a solution using a CustomRenderableSeries. This is my overridden Draw() method:-

    protected override void Draw(Rendering.Common.IRenderContext2D renderContext, IRenderPassData renderPassData)
    {
        // Create the pen.
        var pen = renderContext.CreatePen(SeriesColor, false, StrokeThickness);

        // Iterate through the PointRange.
        var index = renderPassData.PointRange.Min;
        while (index <= renderPassData.PointRange.Max)
        {
            var point = (GenericPoint2D)renderPassData.PointSeries[index];
            if (point == null)
            {
                break;
            }

            // Get data values
            var x = point.X;
            var high = point.YValues.YErrorHigh;
            var low = point.YValues.YErrorLow;

            // Get the data point width, used as the horizontal line length.
            var screenColumnWidth = GetDatapointWidth(renderPassData.XCoordinateCalculator, renderPassData.PointSeries, 1.0);

            // Convert data values to screen/pixel coordinates.
            // The lines need horizontally centring over the points plotted by any XYScatterRenderableSeries that may be present.
            var screenXOffset = screenColumnWidth / 2;
            var screenxFrom = renderPassData.XCoordinateCalculator.GetCoordinate(x) - screenXOffset;
            var screenxTo = screenxFrom + screenColumnWidth;
            var screenylow = renderPassData.YCoordinateCalculator.GetCoordinate(low);
            var screenyhigh = renderPassData.YCoordinateCalculator.GetCoordinate(high);

            // Draw the "low" line.
            var fromPointLow = new PointF((float)screenxFrom, (float)screenylow);
            var toPointLow = new PointF((float)screenxTo, (float)screenylow);
            renderContext.DrawLine(pen, fromPointLow, toPointLow);

            // Draw the "high" line.
            var fromPointHigh = new PointF((float)screenxFrom, (float)screenyhigh);
            var toPointHigh = new PointF((float)screenxTo, (float)screenyhigh);
            renderContext.DrawLine(pen, fromPointHigh, toPointHigh);

            index++;
        }
    }

I’ve wired this up to your ErrorSeriesExampleView in the SciChart example project, and it seems to be rendering correctly, but I wanted to check that what I’m doing is “sound”, i.e. I’m iterating through the correct collection (renderPassData.PointRange), and I’ve not missed anything that may come back to bite me?

Thanks in advance

  • You must to post comments
0
0

Hi Andy,

Good effort! Are you sure this is compiling though? We have this line of code to get the error point out:

var pt = points[i] as GenericPoint2D<HlcSeriesPoint>;

The way ‘GenericPoint’ works is the standard is just X,Y values but for more complex types we had to implement this GenericPoint and have a cast in the inner loop. A bit of a shame but the best we could do to support flexibility and many data/series types.

As of v2.1.1 all the RenderableSeries are no longer sealed, and internalDraw is now protected virtual, so you can keep base type properties if you wish.

Best regards,
Andrew

  • andyste1
    Hi, yes the above is compiling and working fine! That's useful to know about the RenderableSeries no longer being sealed too.
  • andyste1
    I've hit a couple of problems with the above code, and am hoping it's something straightforward. I've now added zoom and pan modifiers to the chart, but I'm finding that my custom series does some strange things when panning and zooming. The main issue is that it renders in the wrong place as I pan to the right. A secondary issue is that the individual lines that are drawn by my series (from one point to the next) draws no longer join together as I zoom. The more I zoom in, the bigger the gap appears between each, resulting in a dashed line effect. I have attached a pdf containing screenshots of both issues, and would be grateful if you could tell me what I'm doing wrong.
  • andyste1
    I've sorted the panning issue. I had made some incorrect assumptions about what "renderPassData.PointSeries" and "renderPassData.PointRange" contained, so my loop logic was incorrect. I've now realised PointSeries only contains the visible points, and therefore only need to iterate through those points:-
    foreach (var pointItem in renderPassData.PointSeries)
    {
        var point = (GenericPoint2D<HlcSeriesPoint>)pointItem;
        if (point == null)
        {
            break;
        }
        ...etc...
    
    However I still have the zoom-in problem (causing the dashed line effect), which I assume to be due to rounding issues, but I'm not sure if it's a problem in my code or SciChart.
  • Andrew Burnett-Thompson
    The zoom in problem is because error bars are not designed to create continuous lines. For that we have other chart types. I just had a thought, seems like you are trying to build a set of thresholds (continuous lines). Why not use one of the following techniques? Horizontal Line Annotation between X1 and X2 Two additional DataSeries with X1Y1 X2Y2 points using Line / Digital Line A Band / Digital Band Series with transparent fills and High/Low values. - Andrew
  • andyste1
    Hi, my screenshot was a poor example as the red "limit lines" were continuous across the entire chart. In reality it'll be possible to define different high/low values for each point, so the lines won't always be continuous. I'm sure the user can live with the gaps that appear when zooming in; alternatively I could make my custom series more sophisticated by examining subsequent points, and if they have the same high (or low) value then draw a single line that spans them all. Thanks for your help anyway.
  • 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