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

SimpleFiltering: Programmatic access to series visibility

4 Answers 87 Views
Chart
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 08 Apr 2011, 03:13 PM
Hi,

I'm looking for ideas/guidance on how I can achieve the following:

I'd like to save which series are visible/hidden on form unload and restore which series are visible/hidden on form load. For this, I'm wondering how I can access the various Series<<seriesname>>Visibility properties in ExampleViewModel (for example, SeriesEU27Visibility, SeriesEuroAreaVisibility, SeriesJapanVisibility, SeriesUSVisibility) so that they can be read on form unload and then set in form load. In addition to setting these properties on form load, I would like to update the form accordingly to display/hide the correponding series and check/uncheck the corresponding check box in the legend.

I'm fairly new to .NET (I've been coding in VBA instead for over 10 years), so the .NET concepts are new, but programming concepts are familiar to me (I know OO programming concepts from Java, but are new to .NET concepts like ViewModels). I'd really appreciate any ideas or guidance on how I can achieve this.

Many thanks in advance!

Kind regards,
Dave.

4 Answers, 1 is accepted

Sort by
0
Accepted
Missing User
answered on 14 Apr 2011, 02:35 PM
Hello David,

You can review the following demo, which gives an example on how to change the Series visibility according to a selected check box. In your case you can save the Series visibility immediately after a check box is clicked, e.g. in the ExampleViewModel.cs -- method ChangeSeriesVisibility(object parameter). You can implement custom logic for saving the visibility and retrieve and set the data in the constructor of the ExampleViewModel.cs. For example:
public ExampleViewModel()
{
    this.WireCommands();
     
    this.RetrieveSeriesVisibility();
}
 
private void FillSampleChartData()
{
    //this.SeriesEU27Visibility = retrieved data
}

You can also review the help topic about MVVM Support here.

I hope this helps.

Kind regards,
Polina
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
David
Top achievements
Rank 2
answered on 15 Apr 2011, 04:01 PM
Hi Polina,

Thanks for getting me started with saving the Series visibility. I'm able to successfully save and retreive the settings, however I have one remaining problem: after retreiving the saved state of the Series visibility, how do I update the checkbox in the legend to the corresponding value?

Here's how I've modified the SimpleFiltering demo (in VB) to save and retrieve the visibility settings:

1. I've added the following four settings to the Chart project properties:
  • Name: SeriesEU27Visibility
    Type: Telerik.Windows.Controls.Charting.SeriesVisibility
    Scope: User
  • Name: SeriesEuroVisibility
    Type: Telerik.Windows.Controls.Charting.SeriesVisibility
    Scope: User
  • Name: SeriesJapanVisibility
    Type: Telerik.Windows.Controls.Charting.SeriesVisibility
    Scope: User
  • Name: SeriesUSVisibility
    Type: Telerik.Windows.Controls.Charting.SeriesVisibility
    Scope: User

2. I have added the following procedure to ExampleViewModel.vb to retrieve the settings:
Private Sub RetrieveSeriesVisibility()
    Me.SeriesEU27Visibility = My.Settings.SeriesEU27Visibility
    Me.SeriesEuroAreaVisibility = My.Settings.SeriesEuroAreaVisibility
    Me.SeriesJapanVisibility = My.Settings.SeriesJapanVisibility
    Me.SeriesUSVisibility = My.Settings.SeriesUSVisibility
End Sub

3. I have modified the constructor to call this procedure:
Public Sub New()
    Me.WireCommands()
    Me.RetrieveSeriesVisibility()
End Sub

4. I have modified the ChangeSeriesVisibility() procedure to save the settings (I also did a little refactoring with a new ToggleSeriesVisibility() function):
Public Sub ChangeSeriesVisibility(ByVal parameter As Object) 
    Dim seriesVisibility As SeriesVisibility 
    Select Case parameter.ToString() 
        Case "EU-27" 
            seriesVisibility = ToggleSeriesVisibility(Me.SeriesEU27Visibility) 
            Me.SeriesEU27Visibility = seriesVisibility 
            My.Settings.SeriesEU27Visibility = seriesVisibility 
            Exit Select 
        Case "Euro area" 
            seriesVisibility = ToggleSeriesVisibility(Me.SeriesEuroAreaVisibility) 
            Me.SeriesEuroAreaVisibility = seriesVisibility 
            My.Settings.SeriesEuroAreaVisibility = seriesVisibility 
            Exit Select 
        Case "Japan" 
            seriesVisibility = ToggleSeriesVisibility(Me.SeriesJapanVisibility) 
            Me.SeriesJapanVisibility = seriesVisibility 
            My.Settings.SeriesJapanVisibility = seriesVisibility 
            Exit Select 
        Case "United States" 
            seriesVisibility = ToggleSeriesVisibility(Me.SeriesUSVisibility) 
            Me.SeriesUSVisibility = seriesVisibility 
            My.Settings.SeriesUSVisibility = seriesVisibility 
            Exit Select 
        Case Else 
            Exit Select 
    End Select 
    My.Settings.Save()    
End Sub 
Private Function ToggleSeriesVisibility(ByVal parameter As SeriesVisibility) As SeriesVisibility 
    Dim seriesVisibility As SeriesVisibility 
    If parameter = seriesVisibility.Collapsed OrElse parameter = seriesVisibility.Hidden Then 
        seriesVisibility = seriesVisibility.Visible 
    Else 
        seriesVisibility = seriesVisibility.Hidden 
    End If 
    Return seriesVisibility 
End Function

These changes successfully save and retrieve the settings. Any suggestions on how to get started to update the check box?

Kind regards,
Dave.
0
Accepted
Missing User
answered on 21 Apr 2011, 11:24 AM
Hello David,

You can set the checkbox values in code behind according to the retrieved data. For example you can get all generated checkboxes and their properties by ChildrenOfType<T> method which is part of the UIElementExtensions Class. In order to use it, you need to include namespace reference to Telerik.Windows.Controls. More information about it can be found here. After you have all generated checkboxes you can make a verification according to their content values and to differentiate them.

Best wishes,
Polina
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
David
Top achievements
Rank 2
answered on 26 Apr 2011, 10:35 AM
Hi Polina,

Thanks for your help! Here's the code I've added to update the checkboxes:

1. I added the following procedure to ExampleViewModel.vb to retrieve the visibility for a specific series based on its content:
Public Function RetrieveSeriesVisibility(ByVal parameter As Object) As SeriesVisibility
    Dim seriesVisibility As SeriesVisibility
    Select Case parameter.ToString()
        Case "EU-27"
            seriesVisibility = Me.SeriesEU27Visibility
            Exit Select
        Case "Euro area"
            seriesVisibility = Me.SeriesEuroAreaVisibility
            Exit Select
        Case "Japan"
            seriesVisibility = Me.SeriesJapanVisibility
            Exit Select
        Case "United States"
            seriesVisibility = Me.SeriesUSVisibility
            Exit Select
        Case Else
            Exit Select
    End Select
    Return seriesVisibility
End Function

2. I've modified Example.xaml to call a loaded event for the user control, ie:
<UserControl
    x:Class="Telerik.Windows.Examples.Chart.SimpleFiltering.Example"
    xmlns:example="clr-namespace:Telerik.Windows.Examples.Chart.SimpleFiltering"
    Loaded="UserControl_Loaded">

3. I added the "UserControl_Loaded" event to Example.xaml.vb:
Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim viewModel As New ExampleViewModel
    For Each checkBox As CheckBox In Me.PrimaryLegend.ChildrenOfType(Of CheckBox)()
        checkBox.IsChecked = viewModel.RetrieveSeriesVisibility(checkBox.Content) = SeriesVisibility.Visible
    Next
End Sub

I hope this helps anyone else who wants to save and retrieve settings for series visibility. Thank you again to Polina for getting me started and helping me achieve this.

Kind regards,
Dave.
Tags
Chart
Asked by
David
Top achievements
Rank 2
Answers by
Missing User
David
Top achievements
Rank 2
Share this question
or