Chart is not reset when I clear Series and do not add new?

2 posts, 1 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 12 May 2011 Link to this post

    Hi telerik

    It would appear to me, that the chart is not redrawn 'without series' if I call radChart.SeriesMappings.Clear() ?

    It may not makes much sense to you what I'm trying, but my users can change the data used for series. Some selections may result in (handled) exceptions where no seriesMappings are added to the radChart.SeriesMappings - and in this case the previous choice of data is still shown to some confusion for my users?

    Anything I can do to reset the chart in this case? Perhaps 'manually'?

    (And, yes - I know that I'm in serious violation of the MVVM in snippet below ;-) ).

    Thanks,

    Anders, Denmark.

     private void UpdateGraphWithViewModel(IGraphViewModel viewModel)
            {
                _loggingService.Log("Drawing graph");

                var numberOfSeries = viewModel.NumberOfSeries;

                // If this is not the first time we are called, the existing must be reset before adding below.
                radChart.SeriesMappings.Clear();
                
                foreach (var selectedVariableY in viewModel.SelectedVariablesY)
                {
                    for (var i = 0; i < numberOfSeries; i++)
                    {
                        try
                        {
                            var pointMarkAppearanceSettings = new PointMarkAppearanceSettings {Shape = MarkerShape.Diamond};
                            var seriesAppearanceSettings = new SeriesAppearanceSettings
                                                               {
                                                                   PointMark = pointMarkAppearanceSettings
                                                               };

                            var interactivitySettings = new InteractivitySettings
                                                            {
                                                                HoverScope = InteractivityScope.Series,
                                                                SelectionScope = InteractivityScope.Series
                                                            };
                            var splineSeriesDefinition = new SplineSeriesDefinition
                                                             {
                                                                 Appearance = seriesAppearanceSettings,
                                                                 InteractivitySettings = interactivitySettings
                                                             };
                            var seriesMapping = new SeriesMapping
                                                    {
                                                        LegendLabel = viewModel.GetLegendHeader(i),
                                                        SeriesDefinition = splineSeriesDefinition,
                                                        ItemsSource = viewModel.GetData(i, selectedVariableY.VariableName)
                                                    };

                            seriesMapping.ItemMappings.Add(new ItemMapping("X", DataPointMember.XValue));
                            seriesMapping.ItemMappings.Add(new ItemMapping("Y", DataPointMember.YValue));

                            radChart.SeriesMappings.Add(seriesMapping);
                        }
                        catch (Exception ex)
                        {
                            var message = string.Format("Error trying to produce serie {0}: {1}", i, ex.Message);
                            _loggingService.Log(message);
                        }
                    }
                }


                var zoomScrollSettingsX = new ZoomScrollSettings
                                              {
                                                  MinZoomRange = 0.1,
                                                  RangeEnd = 1,
                                                  RangeStart = 0,
                                                  ScrollMode = ScrollMode.ScrollAndZoom
                                              };

                var zoomScrollSettingsY = new ZoomScrollSettings
                                              {
                                                  MinZoomRange = 0.1,
                                                  RangeEnd = 1,
                                                  RangeStart = 0,
                                                  ScrollMode = ScrollMode.ScrollAndZoom
                                              };
                radChart.DefaultView.ChartArea.ZoomScrollSettingsX = zoomScrollSettingsX;
                radChart.DefaultView.ChartArea.ZoomScrollSettingsY = zoomScrollSettingsY;

                //radChart.DefaultView.ChartTitle.Content = viewModel.ChartTitle;
                radChart.DefaultView.ChartArea.AxisX.Title = viewModel.AxisTitleX;
                radChart.DefaultView.ChartArea.AxisY.Title = viewModel.AxisTitleY;
                _loggingService.Log("Databinding done. " + string.Format("{0:d/M/yyyy HH:mm:ss:ffff}", DateTime.Now));
            }

  2. Answer
    Tsvetie
    Admin
    Tsvetie avatar
    1498 posts
    Member since:
    Aug 2013

    Posted 17 May 2011 Link to this post

    Hello Anders,
    In this particular case the DataSeries collection is not cleared and even though the series mapping collection of the chart is empty, the chart shows the previous series. You can clear the DataSeries collection manually to fix this the following way:

    radChart.SeriesMappings.Clear();
    radChart.DefaultView.ChartArea.DataSeries.Clear();

    Best wishes,
    Tsvetie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  3. Download a free trial of UI for WPF
Back to Top