ContextMenu on PieChart

5 posts, 0 answers
  1. Tim
    Tim avatar
    3 posts
    Member since:
    Sep 2011

    Posted 16 Sep 2011 Link to this post

    I am developing an application where I need a ContextMenu to appear over a RadChart pie chart. I need to be able to access the DataPoint associated with where the ContextMenu is opened (if any). What is the best approach for this?

    Thanks,
    Tim
  2. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 17 Sep 2011 Link to this post

    Hello Tim,

    Have you seen our topic Integration with RadContextMenu as well as our demo demonstrating the described approach in action? You need to re-template the Pie series type in order to place a RadContextMenu instance as attached property in its template. Here is the default Pie template:

    <Style 
           TargetType="telerikCharting:Pie">
           <Setter Property="Template" >
               <Setter.Value>
                   <ControlTemplate TargetType="telerikCharting:Pie">
                       <Canvas x:Name="PART_MainContainer">
                           <Ellipse Clip="{TemplateBinding FigurePath}" 
                                    Width="{TemplateBinding ItemActualWidth}"
                                    Height="{TemplateBinding ItemActualHeight}"
                                    StrokeThickness="0"
                                    Style="{TemplateBinding ItemStyle}"
                               />
                               <Path x:Name="PART_DefiningGeometry" 
                                 Data="{TemplateBinding FigurePath2}" 
                                 Fill="Transparent"
                                 Style="{TemplateBinding ItemStyle}"/>
                               <Ellipse 
                               Clip="{TemplateBinding FigurePath3}" 
                               Fill="{StaticResource PieMaskBrush}" 
                               Width="{TemplateBinding ItemActualWidth}"
                               Height="{TemplateBinding ItemActualHeight}"
                                                           />
                                   <Canvas.RenderTransform>
                                       <TransformGroup>
                                           <ScaleTransform x:Name="PART_AnimationTransform" ScaleX="0" ScaleY="0" />
                                       </TransformGroup>
                                   </Canvas.RenderTransform>
                                                     </Canvas>
                   </ControlTemplate>
               </Setter.Value>
           </Setter>
       </Style>

    Greetings,
    Evgenia
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. Tim
    Tim avatar
    3 posts
    Member since:
    Sep 2011

    Posted 21 Sep 2011 Link to this post

    I want to have the same context menu for all items in the chart, but be able to know the selected item when the context menu is opened. Is there a simpler way than the above example?
    It would seem like there is a way to get the DataPoint (if any) using RadContextMenu.GetClickedElement<>?

    Thanks,
    Tim
  4. Tim
    Tim avatar
    3 posts
    Member since:
    Sep 2011

    Posted 22 Sep 2011 Link to this post

    I got this to pop-up to ContextMenu, but how do I get the DataPoint (if any) of the item clicked? GetClickedElement?
  5. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 26 Sep 2011 Link to this post

    Hello Tim,

    To get the DataPoint of the clicked Bar you should handle the RadContextMenu_Opened event and use the GetClickedElement<T>() method:

    RadContextMenu menu = (RadContextMenu)sender;
    Bar clickedBar = menu.GetClickedElement<Bar>();
    double clickedBarYValue = clickedBar.DataPoint.YValue;

    Best wishes,
    Evgenia
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top