Using Visibility property for x SplineSeriesDefinitions

2 posts, 0 answers
  1. Roger
    Roger avatar
    1 posts
    Member since:
    Nov 2011

    Posted 17 Nov 2011 Link to this post


    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:

    A MainViewModel exposes this:

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

    A data item is wrapped in this class:

    public class ParameterInspectionViewModel : ViewModelBase
    public RaceData Model
    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:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                                    <telerik:ChartGroupDescriptor Member="Model.Lap"/>
                            <telerik:ItemMapping DataPointMember="XValue" FieldName="Model.Time"></telerik:ItemMapping>
                            <telerik:ItemMapping DataPointMember="YValue" FieldName="Model.Speed"></telerik:ItemMapping>

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

      <telerik:SplineSeriesDefinition Visibility="Visible" />

    Does anybody have a solution to this issue?

    Thank You,

  2. Peshito
    Peshito avatar
    585 posts

    Posted 22 Nov 2011 Link to this post

    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)
                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,
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top