This is a migrated thread and some comments may be shown as answers.

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

3 Answers 1097 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 12 May 2011, 12:28 PM
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));
        }

3 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetie
Telerik team
answered on 17 May 2011, 01:16 PM
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
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 04 Jul 2017, 06:30 AM

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

0
Dilyan Traykov
Telerik team
answered on 06 Jul 2017, 10:05 AM
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 you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Chart
Asked by
Anders
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
jamsheer
Top achievements
Rank 1
Veteran
Dilyan Traykov
Telerik team
Share this question
or