Is a clickable x-axis supported yet?

Thread is closed for posting
3 posts, 0 answers
  1. Eric
    Eric avatar
    48 posts
    Member since:
    Jul 2012

    Posted 13 Jun 2011 Link to this post

    Hello,  I really want to be able to click the xaxis labels and display another menu when that happens.  I read elsewhere that this is not supported yet, but that webpage was back in 2007.  Is this supported now?

    Eric
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 16 Jun 2011 Link to this post

    Hi Eric,
    You can attach a handler for an event of the x-axis items and in that handler, you can execute your code. For example:
    <telerik:RadChart ID="RadChart1" runat="server" OnPrePaint="RadChart1_PrePaint"

    protected void RadChart1_PrePaint(object sender, EventArgs e)
    {
        foreach (var axisItem in RadChart1.PlotArea.XAxis.Items)
        {
            axisItem.ActiveRegion.Attributes = "onclick='alert(1);return false;';";
        }
    }

    In case you want to open a context menu on click of an x-axis item, you can use our RadContextMenu control. For information on RadContextMenu, please refer to the following online resources:

    Best wishes,
    Tsvetie
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aaron King
    Aaron King avatar
    2 posts
    Member since:
    Jan 2010

    Posted 16 Jun 2011 Link to this post

    That's exactly what I was looking for.  I also had this same scenario to work through.  Clicking on the bar area of the bar chart just wasn't enough.  Once the users noticed the charts were clickable, they were frustrated that the text wasn't clickable. 

    I almost switched to jqPlot, but now I can just add this to my existing Telerik charts.  I didn't want to miss the nice downloadable images and better printing that Telerik gives me.  Now I don't have to.

    In order for the x-axis label to follow the same action in the code behind click event for the bar, I added the following code.  I also change the tooltip text a little.  So now my bar and it's label call a code behind method to display a trending chart for the aggregate.

    protected void RadChart1_PrePaint(object sender, EventArgs e)
            {
                foreach (var axisItem in RadChart1.PlotArea.XAxis.Items)
                {
     
                    axisItem.ActiveRegion.Url = "javascript:__doPostBack('" + RadChart1.UniqueID +"','true,0,"+ (axisItem.Value - 1).ToString() + "')";
                    axisItem.ActiveRegion.Tooltip = axisItem.TextBlock.Text.Trim();
                }
            }

Back to Top