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

Axis Label Click Event?

5 Answers 391 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Anthony Ortiz
Top achievements
Rank 1
Anthony Ortiz asked on 19 Nov 2009, 02:32 PM
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

5 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 24 Nov 2009, 09:32 AM
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.
0
Geoffrey
Top achievements
Rank 1
answered on 10 Sep 2012, 12:45 PM
Hi,

Has this ability been implemented in a later version yet?

Regards,
Geoffrey
0
Giuseppe
Telerik team
answered on 11 Sep 2012, 10:51 AM
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.

0
Geoffrey
Top achievements
Rank 1
answered on 12 Sep 2012, 02:46 PM
Hi,

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

Thanks!
0
Giuseppe
Telerik team
answered on 12 Sep 2012, 03:18 PM
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.

Tags
Chart
Asked by
Anthony Ortiz
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Geoffrey
Top achievements
Rank 1
Share this question
or