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

Is a clickable x-axis supported yet?

2 Answers 75 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 14 Jun 2011, 01:23 AM
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 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 16 Jun 2011, 02:18 PM
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.

0
Aaron King
Top achievements
Rank 1
answered on 16 Jun 2011, 03:03 PM
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();
            }
        }

Tags
Chart (Obsolete)
Asked by
Eric
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Aaron King
Top achievements
Rank 1
Share this question
or