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

Getting associated Item Label Text on Drill down click

1 Answer 49 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jeff Miller
Top achievements
Rank 1
Jeff Miller asked on 26 Aug 2008, 02:39 PM
Hello all,

This is concerning determining the label value of a clicked item when drilling down in the Chart.

I am using the Chart with a SQLDataSource.  I would like to be able to determine the label value for the x-axis (label text being generated when bound to sql source) that was clicked so I could use this value to drill down when clicked.  Is this possible or could someone perhaps suggest some creative alternatives?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 28 Aug 2008, 03:19 PM
Hi Jeff Miller,

In order to achieve the desired functionality you need to specify the XValue property for the chart series items (i.e. bind the DataXColumn property of the ChartSeries) and then you need to match this XValue to one of the axis item values on the axis.

Here is a simplified code snippet to get you started:

ASPX:
<telerik:RadChart ID="RadChart1" runat="Server" OnClick="RadChart1_Click"
    <Series> 
        <telerik:ChartSeries Type="Bar"
            <Items> 
                <telerik:ChartSeriesItem XValue="1" YValue="20"
                    <Label TextBlock-Text="Item1" /> 
                </telerik:ChartSeriesItem> 
                <telerik:ChartSeriesItem XValue="2" YValue="30"
                    <Label TextBlock-Text="Item2" /> 
                </telerik:ChartSeriesItem> 
                <telerik:ChartSeriesItem XValue="3" YValue="40"
                    <Label TextBlock-Text="Item3" /> 
                </telerik:ChartSeriesItem> 
            </Items> 
        </telerik:ChartSeries> 
    </Series> 
    <PlotArea> 
        <XAxis AutoScale="false" MinValue="1" MaxValue="3" Step="1"
            <Items> 
                <telerik:ChartAxisItem TextBlock-Text="AxisItem1" Value="1"></telerik:ChartAxisItem> 
                <telerik:ChartAxisItem TextBlock-Text="AxisItem2" Value="2"></telerik:ChartAxisItem> 
                <telerik:ChartAxisItem TextBlock-Text="AxisItem3" Value="3"></telerik:ChartAxisItem> 
            </Items> 
        </XAxis> 
    </PlotArea> 
</telerik:RadChart> 

Code-behind:
protected void RadChart1_Click(object sender, ChartClickEventArgs args) 
    if (args.SeriesItem != null) 
    { 
        // if the axis range is linear e.g. representing axis values 1,2,3 you can use this approach: 
        //ChartAxisItem axisItem = RadChart1.PlotArea.XAxis.Items[(int)args.SeriesItem.XValue - 1]; 
        //Response.Write(axisItem.TextBlock.Text); 
 
        // otherwise you need to use a more generic approach that  
        // iterates over the axis items collection like this: 
        foreach (ChartAxisItem axisItem in RadChart1.PlotArea.XAxis.Items) 
        { 
            if (args.SeriesItem.XValue == (double)axisItem.Value) 
                Response.Write(axisItem.TextBlock.Text); 
        } 
    } 


Hope this helps.


Best wishes,
Manuel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Chart (Obsolete)
Asked by
Jeff Miller
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or