Click event does not fire

3 posts, 1 answers
  1. Marcelo
    Marcelo avatar
    40 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2011 Link to this post

    The data renders just fine but the Click event does not fire...

    XAML below

    <telerikChart:RadChart x:Name="radChartCompanyRevenue" Width="500" Height="350" IsEnabled="True">
        <telerikCharting:ChartDefaultView>
            <telerikCharting:ChartDefaultView.ChartLegend>
                <telerikCharting:ChartLegend Visibility="Collapsed" />
            </telerikCharting:ChartDefaultView.ChartLegend>
            <telerikCharting:ChartDefaultView.ChartArea>
                <telerikCharting:ChartArea ItemClick="ChartArea_ItemClick" />
            </telerikCharting:ChartDefaultView.ChartArea>
        </telerikCharting:ChartDefaultView>
        <telerikChart:RadChart.SeriesMappings>
            <telerikCharting:SeriesMapping>
                <telerikCharting:SeriesMapping.SeriesDefinition>
                    <telerikCharting:PieSeriesDefinition>
                    </telerikCharting:PieSeriesDefinition>
                </telerikCharting:SeriesMapping.SeriesDefinition>
                <telerikCharting:SeriesMapping.ItemMappings>
                    <telerikCharting:ItemMapping DataPointMember="XCategory" FieldName="Month"/>
                    <telerikCharting:ItemMapping DataPointMember="YValue" FieldName="Revenue"></telerikCharting:ItemMapping>
                </telerikCharting:SeriesMapping.ItemMappings>
            </telerikCharting:SeriesMapping>
        </telerikChart:RadChart.SeriesMappings>
    </telerikChart:RadChart>

    C# code below

    // constructor
    public DrillDown_Report()
    {
        InitializeComponent();           
        BindCompanyRevenue();
    }
    private void ChartArea_ItemClick(object sender, Telerik.Windows.Controls.Charting.ChartItemClickEventArgs e)
    {
        CompanyRevenue_Event cr = e.DataPoint.DataItem as CompanyRevenue_Event;
        MessageBox.Show(cr.Month + " " + cr.Revenue.ToString());
    }
    #region Company Revenue
    private void BindCompanyRevenue()
    {
        radChartCompanyRevenue.ItemsSource = this.GetCompanyRevenue();
        radChartCompanyRevenue.DefaultView.ChartTitle.Content = "Company Revenue";
        radChartCompanyRevenue.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;
        radChartCompanyRevenue.DefaultView.ChartArea.ItemClick += new EventHandler<Telerik.Windows.Controls.Charting.ChartItemClickEventArgs>(ChartArea_ItemClick);
    }
    private List<CompanyRevenue_Event> GetCompanyRevenue()
    {
        List<CompanyRevenue_Event> companyRevenue = new List<CompanyRevenue_Event>();
        companyRevenue.Add(new CompanyRevenue_Event(2011, "Jan", 189213.58));
        companyRevenue.Add(new CompanyRevenue_Event(2011, "Feb", 179213.58));
        companyRevenue.Add(new CompanyRevenue_Event(2011, "Mar", 180213.58));
        companyRevenue.Add(new CompanyRevenue_Event(2011, "Apr", 184213.58));
        return companyRevenue;
    }
    #endregion

  2. Answer
    Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 08 Aug 2011 Link to this post

    Hello Marcelo,

    When you are customizing elements within the default view and you are instantiating new ChartDefaultView in XAML, you need to set it to the RadChart.DefaultView property:
    <telerik:RadChart x:Name="radChartCompanyRevenue" Width="500" Height="350">
        <telerik:RadChart.DefaultView>
            <telerik:ChartDefaultView>
                <telerik:ChartDefaultView.ChartLegend>
                    <telerik:ChartLegend Visibility="Collapsed" />
                </telerik:ChartDefaultView.ChartLegend>
                <telerik:ChartDefaultView.ChartArea>
                    <telerik:ChartArea ItemClick="ChartArea_ItemClick" />
                </telerik:ChartDefaultView.ChartArea>
            </telerik:ChartDefaultView>
        </telerik:RadChart.DefaultView>
     
        <telerik:RadChart.SeriesMappings>
            <telerik:SeriesMapping>
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:PieSeriesDefinition>
                    </telerik:PieSeriesDefinition>
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping DataPointMember="XCategory" FieldName="Month"/>
                    <telerik:ItemMapping DataPointMember="YValue" FieldName="Revenue"></telerik:ItemMapping>
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
    </telerik:RadChart>

    Also, you were handling the ItemClick event twice (once in XAML, and once in code-behind) so you will probably need to remove one of the handlers.


    Kind regards,
    Giuseppe
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Marcelo
    Marcelo avatar
    40 posts
    Member since:
    Jul 2011

    Posted 08 Aug 2011 Link to this post

    OK, I see what my problem was. I had not declared RadChart.DefaultView (below)

    <telerikChart:RadChart.DefaultView>

    So the complete XAML for my example is

    <UserControl x:Class="WpfApplication1.UserControls.DrillDown.DrillDown_Dashboard"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting" 
                 xmlns:telerikCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"             
                 mc:Ignorable="d" Width="1024">
          
        <StackPanel>
      
            <telerikChart:RadChart x:Name="radChartCompanyRevenue" VerticalAlignment="Top" Width="500" Height="350">
                  
                <telerikChart:RadChart.DefaultView>
                      
                    <telerikCharting:ChartDefaultView>
                        <telerikCharting:ChartDefaultView.ChartLegend>
                            <telerikCharting:ChartLegend Visibility="Collapsed" />
                        </telerikCharting:ChartDefaultView.ChartLegend>
      
                        <telerikCharting:ChartDefaultView.ChartArea>
                            <telerikCharting:ChartArea ItemClick="ChartArea_ItemClick" PaletteBrushesRepeat="False" >
                            </telerikCharting:ChartArea>
                        </telerikCharting:ChartDefaultView.ChartArea>
                    </telerikCharting:ChartDefaultView>
                      
                </telerikChart:RadChart.DefaultView>
                  
                <telerikChart:RadChart.SeriesMappings>
      
                    <telerikCharting:SeriesMapping>
                        <telerikCharting:SeriesMapping.SeriesDefinition>
                            <telerikCharting:BarSeriesDefinition>
                            </telerikCharting:BarSeriesDefinition>
                        </telerikCharting:SeriesMapping.SeriesDefinition>
                        <telerikCharting:SeriesMapping.ItemMappings>
                            <telerikCharting:ItemMapping DataPointMember="XCategory" FieldName="Month"/>
                            <telerikCharting:ItemMapping DataPointMember="YValue" FieldName="Revenue"></telerikCharting:ItemMapping>
                        </telerikCharting:SeriesMapping.ItemMappings>
                    </telerikCharting:SeriesMapping>
      
                </telerikChart:RadChart.SeriesMappings>
                  
            </telerikChart:RadChart>
      
        </StackPanel>
                  
    </UserControl>
Back to Top