SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Answered
1
0

Hi Guys,

In our application we are using a scatter chart but I have the requirement that only should show the points when X=1. The array of x values only has 0s and 1s.
So you may think that why I am not filtering the array and render it. the problem is that my view has multiple charts which are all zoom synchronized. so In order to archive this all the charts must have the same x and y count values.
So the solution that I am thinking is to find a way where I can draw a transparent points when x=0 and draw red point when x=1.
When I say point I am referring to little rectagles like:

<sciChart:SciChartSurface.RenderableSeries>
<sciChart:XyScatterRenderableSeries RenderTransformOrigin="0.5,0.5">
<sciChart:XyScatterRenderableSeries.PointMarkerTemplate>
<ControlTemplate>
<Rectangle Width="7" Height="7" Fill="Transparent" Stroke="Red" StrokeThickness="1"/>
</ControlTemplate>
</sciChart:XyScatterRenderableSeries.PointMarkerTemplate>
</sciChart:XyScatterRenderableSeries>
</sciChart:SciChartSurface.RenderableSeries>

Can someone help me to do this? or if you have a better solution, please, please let me know….

Thanks very much 🙂

Images
  • You must to post comments
Best Answer
1
0

Update, In SciChart v3.2 we now support the PaletteProvider for scatter charts.

There is a KB article titled Dynamically Change Series Color using PaletteProvider here‘.

Also there is an example which demonstrates this here.

Hope this helps!
Andrew

Images
  • You must to post comments
1
0

Hi Sandra and Andrew,

One more idea for you: you could consider extending CustomRenderableSeries class with your own drawing code, which is quite easy to do for ScatterSeries. Fortunately, we already have an example for ScatterSeries, and after modifying it a bit I received such code:

    public sealed class CustomXyScatterRenderableSeries : CustomRenderableSeries
    {
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            var pointSeries = CurrentRenderPassData.PointSeries;

            // PointMarkers are created once and cached
            var pointMarker = PointMarkerCache;

            if (pointMarker == null)
                return;

            int setCount = pointSeries.Count;

            // Iterate over points collection and render point markers
            for (int i = 0; i < setCount; i++)
            {
                double xPoint = pointSeries[i].X;
                double yPoint = pointSeries[i].Y;

                // If Y != 1, don't draw
                if (yPoint.CompareTo(1d) != 0)
                {
                    continue;
                }

                // Get coordinates for X,Y data values
                var x1 = (int)renderPassData.XCoordinateCalculator.GetCoordinate(xPoint);
                var y1 = (int)renderPassData.YCoordinateCalculator.GetCoordinate(yPoint);

                var pointMarkerRect = new Rect(0, 0, pointMarker.PixelWidth, pointMarker.PixelWidth);
                double xOffset = pointMarkerRect.Width / 2;
                double yOffset = pointMarkerRect.Height / 2;

                // Draw PointMarkers
                renderContext.Blit(new Rect(x1 - xOffset, y1 - yOffset, pointMarkerRect.Width, pointMarkerRect.Height), pointMarker, pointMarkerRect);
            }
        }
}

Hope this helps!

Best regards,
Yuriy

  • vaquita50
    Thanks so much for your help...I have fixed part of my issue by replacing the X values where 0 to (float)double.NaN. so, When the chart is rendered it does not show. but because of this I don't have a X values scale in my Chart as You can see in the image attached. Sorry guys... I hope you can help me with this?By the way... Yuriy, please forget my ignorance by I wanted to try the code that you have a attached but I did not where in my code should I put this code and then where to reference it from? can you give me an idea?Thanks guys... you are awesome :)
  • Yuriy
    Hi Sandra,You should use it instead of ScatterRenderableSeries. It's inherited from CustomRenderableSeries class, which is included into SciChart library. And here is the example of usage:<!-- Create the chart surface --> <SciChart:SciChartSurface Name="sciChart" SciChart:ThemeManager.Theme="Chrome"><!-- Declare RenderableSeries --> <SciChart:SciChartSurface.RenderableSeries> <custom:CustomXyScatterRenderableSeries ResamplingMode="None"><custom:CustomXyScatterRenderableSeries.PointMarkerTemplate> <ControlTemplate> <Ellipse Width="5" Height="5" Fill="#77FF3333" /> </ControlTemplate> </custom:CustomXyScatterRenderableSeries.PointMarkerTemplate></custom:CustomXyScatterRenderableSeries></SciChart:SciChartSurface.RenderableSeries>....Regarding Andrew's suggestion, I think you should try to set the VisibleRange manually (for you have 0,1 values only) or apply a small GrowBy - this should help. Please, try this and let us know if it solves you issue.Best regards, Yuriy
  • vaquita50
    Hi Yuriy...Thanks so much for your help.... You are awesome... I implemented as you suggested with the CustomRenderableSeries class and it works perfectly.... Thanks so much again.... :)
  • Nischal
    Hi Yuriy, is this solution still valid for v3.1. The line rendercontext.Blit is not letting my program to compile.Thanks Nischal
    • Guest
    • 3 years ago
    Hi Nischal, the API has changed since that time and now you could use methods in IPointMarker itself to render PointMarkers on a series. Please take a loo at this thread: https://www.scichart.com/questions/question/custom-point-markers . There are two nice articles mentioned where you can find code snippets showing how to do this.Please feel free to comment if you have any questions.
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.