Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Chart is not reset when I clear Series and do not add new?

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

Feed from this thread
  • Anders avatar

    Posted on May 12, 2011 (permalink)

    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));
            }

    Reply

  • Answer Tsvetie Tsvetie admin's avatar

    Posted on May 17, 2011 (permalink)

    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

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Chart is not reset when I clear Series and do not add new?
Related resources for "Chart is not reset when I clear Series and do not add new?"

WPF Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]