toggle line visibility with scroll and zoom

4 posts, 0 answers
  1. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 26 May 2011 Link to this post

    I create a bunch of lines in a chart and then set them all but the first to invisible like this:

    // set invisible to start with
    for (int i=1 ; i < Chart.DefaultView.ChartArea.DataSeries.Count() ; i++)
        Chart.DefaultView.ChartArea.DataSeries[i].Definition.Visibility = SeriesVisibility.Hidden;

    Visibility of these lines is controlled via checkboxes in a databound listbox in a radexpander and the lines are shown and hidden like this and this works great.

    private void CheckBox_Click(object sender, RoutedEventArgs e)
    {
        CheckBox cb = sender as CheckBox;
        string t = cb.Content.ToString();
        for (int i = 1; i < Chart.DefaultView.ChartArea.DataSeries.Count(); i++)
            if (Chart.DefaultView.ChartArea.DataSeries[i].LegendLabel == t)
            {
                if (cb.IsChecked == false)
                    Chart.DefaultView.ChartArea.DataSeries[i].Definition.Visibility = SeriesVisibility.Hidden;
                else
                    Chart.DefaultView.ChartArea.DataSeries[i].Definition.Visibility = SeriesVisibility.Visible;
                break;
            }
    }

    Things go bad when scroll and zoom get involved ... Zooming or unzooming a section of the chart enables visibility of all the lines which throws all of the checkboxes out of sync...

    Ideas ?
  2. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 31 May 2011 Link to this post

    Hello scott,

    The sample project attached demonstrates how the ZoomScroll feature can be used together with manipulating the Series Visibility. The sample project is based on the Simple Filtering demo.
    You can modify it so that it fits your requirements.
    Some notes about it - it uses the MVVM pattern and the Chart is bound using the Manual Series Mappings as a necessary condition for having ZoomScroll feature.

    Kind regards,
    Evgenia
    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
  3. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 31 May 2011 Link to this post

    Thank you Evgenia.  I'll look at it.   Its probably more elegant than my hooking the zoom/scroll event and forcing a resync.    Here's what I came up with. 

    void ZoomScroll_Changed(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName != "RangeStart" && e.PropertyName != "RangeEnd")
            return;
        RadExpander exp = Expander.ChildrenOfType<RadExpander>().First();
        Telerik.Windows.Controls.ListBox lb = exp.Content as Telerik.Windows.Controls.ListBox;
        var checkboxes = from boxes in lb.Items select boxes;
        if (checkboxes == null) return;
        foreach (SelectorObject SO in checkboxes)
        {
            for (int i = 1; i < TSPredictionChart.DefaultView.ChartArea.DataSeries.Count(); i++)
                if (TSPredictionChart.DefaultView.ChartArea.DataSeries[i].LegendLabel == SO.Description)
                {
                    if (SO.IsChecked == false)
                        TSPredictionChart.DefaultView.ChartArea.DataSeries[i].Definition.Visibility = SeriesVisibility.Hidden;
                    else
                        TSPredictionChart.DefaultView.ChartArea.DataSeries[i].Definition.Visibility = SeriesVisibility.Visible;
                }
        }
    }
  4. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 03 Jun 2011 Link to this post

    Hi scott,

    Let me know how the solution works for you.
    Do not hesitate to contact us if any more questions arise.

    Kind regards,
    Evgenia
    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
Back to Top