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

adding different toolTip to each series

3 Answers 100 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Taraman
Top achievements
Rank 1
Taraman asked on 20 Oct 2010, 12:18 PM
Hello Telerik,

I have created a a bar chart having 2 Y axis
I need to assign a different toolTip to each series

when using :

e.SeriesItem.ActiveRegion.Tooltip = toolTip.ToString();

it assign the toolTip to the two series

I found solution to assign tooltip to the first series

chart.Series[0].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = toolTip.ToString();


but when using the same for the second series as follow:

chart.Series[1][e.SeriesItem.Index].ActiveRegion.Tooltip =

"Hi Series 2";

 

 

 

I get exception:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Source Error:

Line 459: RadChart chart = (RadChart) sender;
Line 460: chart.Series[0].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = toolTip.ToString();
Line 461: chart.Series[1][e.SeriesItem.Index].ActiveRegion.Tooltip = "Hi Series 2";

The following is the complete code:

void 

 

ChartFinancialImpact_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)

 

 

{

 

DataRowView physicianDeviation = (DataRowView)e.DataItem;

 

 

 

StringBuilder toolTip = new StringBuilder();

 

 

 

toolTip.Append("Load:" + physicianDeviation["PhysicianLoad"].ToString() );

 

 

 

//e.SeriesItem.ActiveRegion.Tooltip = toolTip.ToString();

 

 

 

RadChart chart = (RadChart) sender;

 

 

  chart.Series[0].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = toolTip.ToString();

 

  //chart.Series[1][e.SeriesItem.Index].ActiveRegion.Tooltip = "Hi Series 1";  ==> ERROR

 

 

}

 

 


3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 22 Oct 2010, 02:09 PM
Hello Taraman,

I was able to reproduce your issue. The reason for this error is that you are trying to set Tooltip for two series one right after another by using e.SeriesItem.Index. Have in mind that ItemDataBound event is called on every new Series. This means that when you set:
chart.Series[1][e.SeriesItem.Index].ActiveRegion.Tooltip = "Hi Series 2"; 
you are still indexing your first Series.
To set tooltip for second Series you should ensure that you are indexing the second series:
protected void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        RadChart1.Series[0].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = "Series 1";
        if (e.SeriesItem.Parent.Name == "Series 2")
        {
            RadChart1.Series[1].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = "Series 2";
        }
    }

I hope this helps.

Greetings,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Taraman
Top achievements
Rank 1
answered on 23 Oct 2010, 07:11 PM
Hello Telerik,

I found also another solution for this problem, it is working but I need to know if it is a valid solution (performance)

void ChartFinancialImpact_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
        {
                    
            RadChart chart = (RadChart) sender;
            chart.Series[0].Items[e.SeriesItem.Index].ActiveRegion.Tooltip = "Series 1";
            if (chart.Series[1].Items.Count > 0)
                chart.Series[1].Items[e.SeriesItem.Index].ActiveRegion.Tooltip ="Series 2";
        }

thanks
Mohamed Taraman
0
Evgenia
Telerik team
answered on 27 Oct 2010, 08:33 AM
Hi Taraman,

Your solution is correct too. You can choose any of these approaches to show Tooltip for second Chart series. 

All the best,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart (Obsolete)
Asked by
Taraman
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Taraman
Top achievements
Rank 1
Share this question
or