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

ContextMenu on PieChart

4 Answers 74 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 16 Sep 2011, 09:38 PM
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

4 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 17 Sep 2011, 02:50 PM
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 >>
0
Tim
Top achievements
Rank 1
answered on 21 Sep 2011, 04:28 PM
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
0
Tim
Top achievements
Rank 1
answered on 22 Sep 2011, 10:58 PM
I got this to pop-up to ContextMenu, but how do I get the DataPoint (if any) of the item clicked? GetClickedElement?
0
Evgenia
Telerik team
answered on 26 Sep 2011, 03:53 PM
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 >>
Tags
Chart
Asked by
Tim
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Tim
Top achievements
Rank 1
Share this question
or