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

RadChart SeriesMapping Problems

1 Answer 75 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Marie C
Top achievements
Rank 1
Marie C asked on 05 Feb 2013, 05:36 PM

In my application, the user is allowed to make selections from a treeview.  Once the user clicks the Search button, up to three views are searched for the data.  The WCF returned data from each view is added to a list which contains the SensorName, TimeStamp and SelectedFieldValue. When all the data has been added to the list, CreateChart() is called.  It loops through each unique SensorName and creates a series. The goal is to chart each sensorName as a different line series.  This works with the DataSeries but not with seriesMapping.  I can't use DataSeries because I could have thousands of points for each line and am using sampling and zoom/scroll in the chart.  According to Telerik, ItemMapping is required for this. 

The result is the legend does not clear the old data and the chart keeps the old DataSeries and adds the new one if the user performs another search.  I think the problem is the way I am looping over SeriesMapping.  Any help would be greatly appreciated.

private void CreateChart()
   {
     int waitingForComplete = (from x in viewsCalled
                               select x).Distinct().Count();
     if (processComplete == waitingForComplete)
     {
       if(chartData.Count == 0)
       {
         MessageBox.Show("No records were returned for the selected dates.");
       }
       else
       {         
         #region Sampling and zooming
         //AVERAGES THE VALUES IN ORDER TO DRAW FASTER
         ItemMapping itemMapping = new ItemMapping("SelectedFieldValue", DataPointMember.YValue);
         itemMapping.SamplingFunction = ChartSamplingFunction.Max;
         chartName.SamplingSettings.SamplingThreshold = 150;
          //ZOOMSCROLL FUNCTION
         chartName.DefaultView.ChartArea.ZoomScrollSettingsX.MinZoomRange = 0.01;
         chartName.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.ScrollAndZoom;
         #endregion Sampling and zooming
         // CREATE THE LINE SERIES
         List<string> sensorReturned = new List<string>();
         //int sensorCount = (from x in chartData
         //                   select x.SensorName).Distinct().Count();
         // GET A LIST OF THE SENSOR NAMES RETURNED
         sensorReturned = (from x in chartData
                           select x.SensorName).Distinct().OrderBy(x => x).ToList();
         int i = 0;
         sensorChartCollection.Clear();
         foreach(var sensorItem in sensorReturned)
         {  
           // CREATE ADDITIONAL YAXIS'
           if (i == 0)
           {
             chartName.DefaultView.ChartArea.AxisY.Title = sensorItem;
           }
           else
           {
             AxisY axisY = new AxisY();
             axisY.AxisName = "AxisY_" + sensorItem;
             axisY.Title = sensorItem;
             chartName.DefaultView.ChartArea.AdditionalYAxes.Add(axisY);
           }
           // DISABLE ANIMATIONS TO SPEED UP THE CHART DRAW
           chartName.DefaultView.ChartArea.EnableAnimations = false;
           SeriesMapping seriesMapping = new SeriesMapping(); 
           sensorChartCollection.Add(GetSensorData(sensorItem.ToString()));
           seriesMapping.CollectionIndex = i;
           seriesMapping.LegendLabel = sensorItem;
           seriesMapping.SeriesDefinition = new LineSeriesDefinition();
           if (i != 0) seriesMapping.SeriesDefinition.AxisName = "AxisY_" + sensorItem;
           seriesMapping.ItemMappings.Add(new ItemMapping("TimeStamp", DataPointMember.XValue));  // XCATEGORY CAN NOT BE SAMPLED
           seriesMapping.ItemMappings.Add(new ItemMapping("SelectedFieldValue", DataPointMember.YValue));
           seriesMapping.ItemMappings.Add(new ItemMapping("SelectedFieldValue", DataPointMember.Tooltip));
           chartName.SeriesMappings.Add(seriesMapping);
           i++;     
           #region commented out
           //var sensorPlotItems = (from p in chartData
           //                       where p.SensorName == sensorItem
           //                       select p).ToList();
           //DataSeries lineSeries = new DataSeries();
           //lineSeries.LegendLabel = sensorItem.ToString();
           //lineSeries.Definition = new LineSeriesDefinition { ShowPointMarks = false, ShowItemToolTips = true, ShowItemLabels = false };
           ////lineSeries.Definition.ShowItemLabels = false;  // REMOVE THE LABELS FOR EACH POINT
           ////lineSeries.Definition.ShowItemToolTips = true; // SHOW TOOLTIPS ON MOUSEOVER  
           // if(i != 0) lineSeries.Definition.AxisName =  "AxisY_" + sensorItem;
           //lineSeries.Definition.Appearance.PointMark.Shape = MarkerShape.Diamond;
           //foreach (var item in sensorPlotItems)
           //{
           //  lineSeries.Add(new DataPoint() { XCategory = item.TimeStamp.ToString(), YValue = item.SelectedFieldValue, LegendLabel = sensorItem.ToString(), Tooltip = item.SelectedFieldValue.ToString() });
           //}
           //chartName.DefaultView.ChartArea.DataSeries.Add(lineSeries);
           //i++;    
           #endregion
                  
         }
         int dataSerCount = chartName.DefaultView.ChartArea.DataSeries.Count();
         chartName.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM-yyyy hh:mm tt";
         chartName.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;         
       }
       chartName.ItemsSource = sensorChartCollection;
       busy.IsBusy = false;      
     }
   }

 

1 Answer, 1 is accepted

Sort by
0
Marie C
Top achievements
Rank 1
answered on 07 Feb 2013, 04:51 PM
Problem solved. 

I needed to clear the seriesMapping of the chart before adding new ones. I added  chartName.SeriesMappings.Clear(); before the foreach loop.
Tags
Chart
Asked by
Marie C
Top achievements
Rank 1
Answers by
Marie C
Top achievements
Rank 1
Share this question
or