Removing a DataPoint from a chart series?

2 posts, 0 answers
  1. Eitan
    Eitan avatar
    26 posts
    Member since:
    Jun 2012

    Posted 19 Oct 2014 Link to this post

    Hi,

    I developed a Windows Phone 8 application: "Take A Hike" where one of the features is to track the user movement.

    I created a RadCartesianChart with two series of DataPoints: Distance(X) vs. Elevation(Y) and Distance(X) vs. Speed(Y).

    I would like to limit the series size to fixed amount of points, i.e. 300 points.

    Aa data is being collected, I would like to draw all points if the total number of points is less than 300 or if the number of points is 300 to remove the first point and add the last point.

    The chart is defined like this:

    <telerikChart:RadCartesianChart x:Name="TrackByDistanceChart"
                                    Grid.Row="2"
                                    Background="Bisque"
                                    Height="200"
                                    Margin="0,0,0,6">
     
        <!--Zoom and Pan-->
        <telerikChart:RadCartesianChart.Behaviors>
            <telerikChart:ChartPanAndZoomBehavior ZoomMode="Horizontal"
                                                  PanMode="Horizontal" />
        </telerikChart:RadCartesianChart.Behaviors>
     
        <!--Horizontal Axis-->
        <telerikChart:RadCartesianChart.HorizontalAxis>
            <telerikChart:LinearAxis HorizontalAlignment="Center"
                                     LabelFitMode="Rotate"
                                     LabelRotationAngle="315"
                                     Style="{StaticResource LinearAxisStyle}" />
        </telerikChart:RadCartesianChart.HorizontalAxis>
     
        <!--Verical Axis-->
        <telerikChart:RadCartesianChart.VerticalAxis>
            <telerikChart:LinearAxis VerticalAlignment="Center"
                                     Style="{StaticResource LinearAxisStyle}" />
        </telerikChart:RadCartesianChart.VerticalAxis>
     
        <!--Grid-->
        <telerikChart:RadCartesianChart.Grid>
            <telerikChart:CartesianChartGrid MajorLinesVisibility="XY"
                                             MajorXLinesRenderMode="All"
                                             Style="{StaticResource GridStyleDashedAll}">
     
                <telerikChart:CartesianChartGrid.MajorXLineStyle>
                    <Style TargetType="Line">
                        <Setter Property="Stroke"
                                Value="{StaticResource SolidBlackBrush}" />
                    </Style>
                </telerikChart:CartesianChartGrid.MajorXLineStyle>
     
                <telerikChart:CartesianChartGrid.MajorYLineStyle>
                    <Style TargetType="Line">
                        <Setter Property="Stroke"
                                Value="{StaticResource SolidBlackBrush}" />
                    </Style>
                </telerikChart:CartesianChartGrid.MajorYLineStyle>
            </telerikChart:CartesianChartGrid>
     
        </telerikChart:RadCartesianChart.Grid>
     
        <!--Scatter Line-->
        <telerikChart:ScatterLineSeries Stroke="Red"
                                        StrokeThickness="2"
                                        ClipToPlotArea="False">
        </telerikChart:ScatterLineSeries>
     
        <telerikChart:ScatterLineSeries Stroke="Blue"
                                        StrokeThickness="2"
                                        ClipToPlotArea="False">
     
            <telerikChart:ScatterLineSeries.VerticalAxis>
                <telerikChart:LinearAxis HorizontalLocation="Right"
                                         VerticalAlignment="Center"
                                         Style="{StaticResource LinearAxisStyle}" />
            </telerikChart:ScatterLineSeries.VerticalAxis>
     
        </telerikChart:ScatterLineSeries>
     
    </telerikChart:RadCartesianChart>

    The code to add the points is done like this:

    trackByDistanceChartSeries0.DataPoints.Add( new ScatterDataPoint { XValue = Distance, YValue = Elevation} );
    trackByDistanceChartSeries1.DataPoints.Add( new ScatterDataPoint { XValue = Distance, YValue = Speed    } );


    Can I remove the first points from the series and add the new points?

    trackByDistanceChartSeries0.DataPoints.RemoveAt( 0 );
    trackByDistanceChartSeries1.DataPoints.RemoveAt( 0 );
     
    trackByDistanceChartSeries0.DataPoints.Add( new ScatterDataPoint { XValue = Distance, YValue = Elevation } );
    trackByDistanceChartSeries1.DataPoints.Add( new ScatterDataPoint { XValue = Distance, YValue = Speed     } );

    Will the chart update itself as I remove and add the new points?

    I am trying to save time loading all the points (300) to the chart as I get a new points.

    Thanks
    Eitan



















  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 22 Oct 2014 Link to this post

    Hi Eitan,

    What you have shown is a perfectly valid approach and I would not expect any issues with it. Yes, RadChart will be updated when you remove a point and then add a new one.

    Best regards,
    Ves
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
Back to Top