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

toggle line visibility with scroll and zoom

3 Answers 71 Views
Chart
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 26 May 2011, 01:48 PM
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 ?

3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 31 May 2011, 12:13 PM
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
0
scott
Top achievements
Rank 1
answered on 31 May 2011, 02:47 PM
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;
            }
    }
}
0
Evgenia
Telerik team
answered on 03 Jun 2011, 07:56 AM
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
Tags
Chart
Asked by
scott
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
scott
Top achievements
Rank 1
Share this question
or