Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Chart > Chart Sereis Events

Answered Chart Sereis Events

Feed from this thread
  • Abdulhameed avatar

    Posted on Jan 3, 2012 (permalink)

    I would like to attach a mouse leave event on the series \ item in a chart.
    I manged to attache the mouse leave event on the chartarea however I would like to attache it to a series or even an item if possible.

    Reply

  • Answer Yavor Yavor admin's avatar

    Posted on Jan 5, 2012 (permalink)

    Hello Abdulhameed,

    You can achieve your scenario by using behavior, attached to the chart series item. Enabling this attached behavior can be done by using ItemStyle. Here is an example of an attached behavior class:

    public static class MouseBehavior
    {
        public static bool GetIsMouseLeaveAttached(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsMouseLeaveAttachedProperty);
        }
     
        public static void SetIsMouseLeaveAttached(DependencyObject obj, bool value)
        {
            obj.SetValue(IsMouseLeaveAttachedProperty, value);
        }
     
        // Using a DependencyProperty as the backing store for IsMouseLeaveAttached.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsMouseLeaveAttachedProperty =
            DependencyProperty.RegisterAttached("IsMouseLeaveAttached", typeof(bool), typeof(BaseChartItem), new PropertyMetadata(OnIsMouseLeaveAttachedChanged));
     
        private static void OnIsMouseLeaveAttachedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BaseChartItem chartItem = sender as BaseChartItem;
            if ((bool)e.NewValue)
            {
                chartItem.MouseLeave += chartItem_MouseLeave;
            }
            else
            {
                chartItem.MouseLeave -= chartItem_MouseLeave;
            }
        }
     
        static void chartItem_MouseLeave(object sender, MouseEventArgs e)
        {
            BaseChartItem chartItem = sender as BaseChartItem;
            MessageBox.Show(string.Format("Mouse leave Y{0}", chartItem.DataPoint.YValue));
        }
    }

    You can attach this behavior to any class that derives from BaseChartItem. Here is how you can attach it in markup:
    <telerik:BarSeriesDefinition>
        <telerik:BarSeriesDefinition.ItemStyle>
            <Style TargetType="telerik:BaseChartItem">
                <Setter Property="local:MouseBehavior.IsMouseLeaveAttached" Value="True" />
            </Style>
        </telerik:BarSeriesDefinition.ItemStyle>
    </telerik:BarSeriesDefinition>

    I have attached a small demo project that demonstrates this approach. If you have any trouble with it I will be happy to assist you.

    Kind regards,
    Yavor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • Abdulhameed avatar

    Posted on Jan 28, 2012 (permalink)

    This is great, In addition I would like to have the event to send data back to the main control. In other words based on the data item entered I would like to alter another chart or control.

    As an end result I would like to have two charts, When I hover over the first chart data item, it updates the second chart.

    Reply

  • Answer Petar Marchev Petar Marchev admin's avatar

    Posted on Feb 1, 2012 (permalink)

    Hi,

    In the chartItem_MouseLeave method you can add the following code
    MainPage mainPage = Telerik.Windows.Controls.ParentOfTypeExtensions.GetVisualParent<MainPage>(chartItem);
    mainPage.HandleMouseLeave(chartItem);

    And you will need to define the HandleMouseLeave method in your user control, where you can place your logic on updating the second chart.

    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Chart > Chart Sereis Events
Related resources for "Chart Sereis Events"

Silverlight Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]