Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change and display a tooltip on a chart in c# when the mouse hovers over a bar?

Tags:

c#

tooltip

charts

I have a System.Windows.Forms.DataVisualization.Charting.chart and I want to show some information about a bar on the chart when you hover over it. But I can't see where to set a tooltip.

I can set this chart3.Series[0].ToolTip = "hello world";

but how do I pick up which x or y value I am hovering over in order to modify the text?

like image 983
Kevin Badger Avatar asked Aug 19 '12 09:08

Kevin Badger


1 Answers

I'm surprised nobody mentioned the simple and standard solution yet so I'm compelled to answer a 5 year-old question.

Just add chart keywords to the tooltip string. They get automatically replaced by values of the points you hover over. Something like this:

chart3.Series[0].ToolTip = "hello world from #VALX, #VAL";

These should cover almost all chart tooltip use cases. For the rare cases they don't cover, you can use what the other answers suggest.

More info: https://msdn.microsoft.com/en-us/library/dd456687.aspx

like image 59
relatively_random Avatar answered Oct 05 '22 23:10

relatively_random