Axis Label Click Event?

6 posts, 1 answers
  1. Anthony Ortiz
    Anthony Ortiz avatar
    8 posts
    Member since:
    Nov 2009

    Posted 19 Nov 2009 Link to this post

    Hello,

    The ChartArea's ItemClick event works great, but I now have an issue where if the value is too small (in a BarSeriesDefinition) then the bar won't display at all and the user is unable to click on anything. In those cases where the value is too small to display a visual, is it possible to make it so that the user can at least click on the Axis label?

    Regards,

    Anthony
  2. Answer
    Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 24 Nov 2009 Link to this post

    Hi Anthony,

    Unfortunately RadChart does not support this functionality at the moment and it will not be possible to achieve the desired effect. Nevertheless, we will forward your inquiry to our developers so they can consider it for one of the future versions of the control.


    Sincerely yours,
    Manuel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Geoffrey
    Geoffrey avatar
    23 posts
    Member since:
    Mar 2011

    Posted 10 Sep 2012 Link to this post

    Hi,

    Has this ability been implemented in a later version yet?

    Regards,
    Geoffrey
  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 11 Sep 2012 Link to this post

    Hello Geoffrey,

    We haven't implemented built-in support for this scenario but you can add a custom style for the SeriesItemLabel element that will enable you to click on it if the respective series item element is too small:

    XAML
    <Window x:Class="WpfApplication3.MainWindow"
            Title="MainWindow" Height="350" Width="525">
     
        <Grid x:Name="LayoutRoot">
            <Grid.Resources>
                <Style x:Key="CustomLabelStyle" TargetType="telerik:SeriesItemLabel">
                    <Setter Property="IsHitTestVisible" Value="True"/>
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"
                                           TextAlignment="Center"
                                           Cursor="Hand"
                                           MouseLeftButtonDown="TextBlock_MouseLeftButtonDown" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
     
            <telerik:RadChart x:Name="RadChart1" />
     
        </Grid>
    </Window>

    C#
    using System.Windows;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.Charting;
     
    namespace WpfApplication3
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
     
                RadChart1.DefaultSeriesDefinition = new BarSeriesDefinition() { SeriesItemLabelStyle = this.LayoutRoot.Resources["CustomLabelStyle"] as Style };
                RadChart1.ItemsSource = new int[] { 1, 2, 200, 1000 };
                RadChart1.DefaultView.ChartArea.ItemClick += new System.EventHandler<ChartItemClickEventArgs>(ChartArea_ItemClick);
            }
     
            private void ChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
            {
                // Get the corresponding data point
                DataPoint dataPoint = e.DataPoint;
            }
     
            private void TextBlock_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                TextBlock textBlockVisual = sender as TextBlock;
                SeriesItemLabel label = textBlockVisual.GetVisualParent<SeriesItemLabel>();
     
                // Get the corresponding data point
                DataPoint dataPoint = label.DataContext as DataPoint;
            }
        }
    }

    Hope this helps.


    Kind regards,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Geoffrey
    Geoffrey avatar
    23 posts
    Member since:
    Mar 2011

    Posted 12 Sep 2012 Link to this post

    Hi,

    I actually meant the x-axis label at the bottom of the chart, but this will work as well.

    Thanks!
  7. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 12 Sep 2012 Link to this post

    Hello Geoffrey,

    Generally the axis labels are not associated with the series items so it would not be that easy to extract the respective data point as in the demonstrated approach with the series item label.


    Regards,
    Giuseppe
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Back to Top
UI for WPF is Visual Studio 2017 Ready