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

Using Visibility property for x SplineSeriesDefinitions

1 Answer 16 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 17 Nov 2011, 05:35 PM

Hello,

I'm evaluating RadChart and I'm not sure if it is my ticket to success... The facts at hand:

There is an entity with columns as shown here: Lap, Time, Speed, Brake, etc. Sample data with 5 snapshots (I don't know the number of laps):

0, 1256, 56, 10
0, 1456, 55, 0
0, 2156, 63, 0
1, 5512, 121, 54
1, 5699, 110, 96

My attempt is to group the data by "Lap" and visualize each group in a SplineSeriesDefinition. Next, the user can enable/disable a group as shown here: http://demos.telerik.com/silverlight/#Chart/SimpleFiltering

A MainViewModel exposes this:

public ObservableCollection<ParameterInspectionViewModel> Snapshots
{
    get
    {
        return _snapshots;
    }
    set
    {
        if (_snapshots != value)
        {
            _snapshots = value;
            RaisePropertyChanged(() => Snapshots);
        }
    }
}

A data item is wrapped in this class:

public class ParameterInspectionViewModel : ViewModelBase
{
public RaceData Model
{
get;
private set;
}
public ParameterInspectionViewModel(RaceData model)
{
Model = model;
}
public const string DirtyVisibilityPropertyName = "DirtyVisibility";
private Visibility _dirty = Visibility.Collapsed;
...
}

Here is my RadChart:

<telerik:RadChart x:Name="SingleLapChart" ItemsSource="{Binding Snapshots}">
            <telerik:RadChart.SeriesMappings>
                <telerik:SeriesMapping>
                     
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:SplineSeriesDefinition></telerik:SplineSeriesDefinition>
                    </telerik:SeriesMapping.SeriesDefinition>
                     
                    <telerik:SeriesMapping.GroupingSettings>
                        <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                            <telerik:GroupingSettings.GroupDescriptors>
                                <telerik:ChartGroupDescriptor Member="Model.Lap"/>
                            </telerik:GroupingSettings.GroupDescriptors>
                        </telerik:GroupingSettings>
                    </telerik:SeriesMapping.GroupingSettings>
 
                    <telerik:SeriesMapping.ItemMappings>
                        <telerik:ItemMapping DataPointMember="XValue" FieldName="Model.Time"></telerik:ItemMapping>
                        <telerik:ItemMapping DataPointMember="YValue" FieldName="Model.Speed"></telerik:ItemMapping>
                    </telerik:SeriesMapping.ItemMappings>
                </telerik:SeriesMapping>
                 
            </telerik:RadChart.SeriesMappings>

I can't use the Visibility property since the DataContext isn't that of the rendered group:

<telerik:SeriesMapping.SeriesDefinition>
  <telerik:SplineSeriesDefinition Visibility="Visible" />
</telerik:SeriesMapping.SeriesDefinition>

Does anybody have a solution to this issue?

Thank You,
Roger

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 22 Nov 2011, 03:07 PM
Hi Roger,

Chart's series definitions do not inherit from the FrameworkElement class. Therefore you cannot apply binding in code behind. What you could do is to wire to the check box Checked and Unchecked events and control each series visibility by using the check box CommandParameter in order to find what checkbox is checked and this way to set your desired series visibility. You should also know the order of which your items are passed in order to properly define the order of the series that should be hidden.

For example:
private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if ((sender as CheckBox).CommandParameter == null)
                return;
 
            if ((sender as CheckBox).CommandParameter.ToString() == "0")
            {
                RadChart1.DefaultView.ChartArea.DataSeries[0].Definition.Visibility = SeriesVisibility.Visible;
            }
 
            else if ((sender as CheckBox).CommandParameter.ToString() == "1")
            {
                RadChart1.DefaultView.ChartArea.DataSeries[1].Definition.Visibility = SeriesVisibility.Visible;
            }
        }
 
        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if ((sender as CheckBox).CommandParameter.ToString() == "0")
            {
                RadChart1.DefaultView.ChartArea.DataSeries[0].Definition.Visibility = SeriesVisibility.Hidden;
            }
 
            else if ((sender as CheckBox).CommandParameter.ToString() == "1")
            {
                RadChart1.DefaultView.ChartArea.DataSeries[1].Definition.Visibility = SeriesVisibility.Hidden;
            }
        }

Hope this helps.

All the best,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Chart
Asked by
Roger
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or