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

4 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
    1517 posts

    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. jamsheer
    jamsheer avatar
    36 posts
    Member since:
    Feb 2017

    Posted 04 Jul Link to this post

    Hello Telerik
            Here I have a chart view for showing the model of chart ,That means where I have dropdownlists with chart type names and Chart view for showing the selected chart type of Dropdownlist. Its works successfully.
    When I select Scatter Area Chart at first time then it showing successfully ,But Getting Error like that is "CartesianSeries can be attached to CartesianView" if I selected Scatter Area Chart Not at first Time.

           I attached the pic of Exception.
    How could I Overcome This exception.

    Thanks 
    Jamsheer

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    570 posts

    Posted 06 Jul Link to this post

    Hello jamsheer,

    From the exception you've described, it seems that you're using the ChartView for WinForms control. Please note, however, that this forum targets the RadChart for WPF control.

    May I kindly ask you to open a new forum or support thread and set the correct product so that you get adequate help. Thank you for your cooperation and understanding.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top