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

Filter SeriesMapping?

5 Answers 100 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jason Heine
Top achievements
Rank 1
Jason Heine asked on 22 Sep 2010, 07:50 PM
Hello,

I am having issues with filtering out a SeriesMapping from the RadChart.

First of all, I have groups of data, which are stored in a:

List<ObservableCollection<OData>>


My T is a class called OData:

public class OData
{
    public string PlantName { get; set; }
    public string Quarter { get; set; }
    public double IndicatorValue { get; set; }
}

Now, I fill this data and return a collection of multiple OData classes.

When I build the chart, I am building a series map for each OData in the collection:

ISeriesDefinition seriesDefinition = DetermineDefinition();
                seriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
                seriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
 
                 
                var series = new SeriesMapping
                {
                    SeriesDefinition = seriesDefinition,
                    LegendLabel = plant.PlantName,
                };
 
                series.ItemMappings.Add(new ItemMapping("IndicatorValue", DataPointMember.YValue));
                series.ItemMappings.Add(new ItemMapping("Quarter", DataPointMember.XCategory));
                 
                series.CollectionIndex = counter;
                radChart.SeriesMappings.Add(series);


Now, the problem comes in when I got to filter out one of the series. I have a ListBox (with check boxes as a template). Here is the code for the CheckBox_Unchecked event:

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            var sourceCheckbox = e.OriginalSource as CheckBox;
            radChart.FilterDescriptors.Add(new ChartFilterDescriptor("PlantName", typeof(string), FilterOperator.IsNotEqualTo, sourceCheckbox.Content));
        }

What happens here is I get an error indicating PlantName does not exist in the ObservableCollection.

I am displaying the "Quarter" as the X-Axis labels, the "Indicator Value" as the Y-Axis and the Series should be identified as PlantName.

Any thought on how I can filter out each of my series?

Thanks,

Jason

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 27 Sep 2010, 09:48 AM
Hi Jason Heine,

FilterDescriptors are used to filter items within the series. If you need to filter out entire series you can do this easily by just removing the series mapping in your Unchecked event handler like this:

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
    var sourceCheckbox = e.OriginalSource as CheckBox;
    RadChart1.SeriesMappings.Remove(RadChart1.SeriesMappings.SingleOrDefault(c => c.LegendLabel == sourceCheckbox.Content as string));
}

Best wishes,
Yavor Ivanov
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
Jason Heine
Top achievements
Rank 1
answered on 28 Sep 2010, 02:21 PM
Hello,

Thanks for the response. The problem with your solution is you are just removing the series. If I want to add it back, I have to go through hoops to do so.

I think I have a different solution that works.

Here is my code (it may not be the most elegant, but it works):

private void CheckBox_Checked(object sender, RoutedEventArgs e)
       {
           var sourceCheckbox = e.OriginalSource as CheckBox;
           if (sourceCheckbox != null)
           {
               foreach (DataSeries series in radChart.DefaultView.ChartArea.DataSeries)
               {
                   if (sourceCheckbox.Content != null)
                   {
                       if (series.LegendLabel == sourceCheckbox.Content.ToString())
                       {
                           series.Definition.Visibility = SeriesVisibility.Visible;
                       }
                   }
               }
           }
       }
       private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
       {
           var sourceCheckbox = e.OriginalSource as CheckBox;
           foreach (DataSeries series in radChart.DefaultView.ChartArea.DataSeries)
           {
               if (series.LegendLabel == sourceCheckbox.Content.ToString())
               {
                   series.Definition.Visibility = SeriesVisibility.Hidden;
               }
           }
       }

If you know of a more elegant solution, by all means, let me know.

Thanks,

Jason
0
Yavor
Telerik team
answered on 30 Sep 2010, 03:29 PM
Hello Jason Heine,

I am glad that you have found a solution to your problem. When you are hiding / showing the series they will appear instantly without animation compared to when you are adding / removing them. Showing / hiding also will visualize the series quicker, because the series is already created and no binding has to be made.

There is one optimization that you can apply for quicker visualization if you have multiple series with lots of data that have to be created when you start your application. To speed up the initial loading (of course if you need only a few series displayed initially) you can add only the series that are not added yet and change the visibility accordingly. This way your checked event handler can look like this:

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    CheckBox checkBox = (sender as CheckBox);
    string plant = checkBox.Content as string;
    bool isChecked = checkBox.IsChecked.Value;
 
    if (!this.plantCollectionDict.ContainsKey(plant))
    {
        // this series is not added yet
        this.plantCollectionDict[plant] = this.RadChart1.SeriesMappings.Count;
        data.Add(CreateData(plant));
        RadChart1.SeriesMappings.Add(CreateMapping(plant));
    }
 
    plantVisibilityDict[plant] = (isChecked ? SeriesVisibility.Visible : SeriesVisibility.Hidden);
 
    foreach (KeyValuePair<string, SeriesVisibility> pair in plantVisibilityDict)
    {
        RadChart1.DefaultView.ChartArea.DataSeries.Single(c => c.LegendLabel == pair.Key).Definition.Visibility = pair.Value;
    }
}

I have attached a sample application that demonstrates this approach. It has 10 plants, each with 1000 items.
I hope this helps.

 

Sincerely yours,
Yavor Ivanov
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
Jason Heine
Top achievements
Rank 1
answered on 30 Sep 2010, 03:37 PM
Thank you for the code example. I appreciate it.
0
Yavor
Telerik team
answered on 04 Oct 2010, 07:49 AM
Hello Jason Heine,

We are glad that your issue is now resolved. Don't hesitate to contact us if you have other questions!

Best wishes,
Yavor Ivanov
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
Tags
Chart
Asked by
Jason Heine
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Jason Heine
Top achievements
Rank 1
Share this question
or