Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show tooltip in LineSeries WinForms Chart?

I am working on a Dashboard System where i am using Line Chart in WinForms. I need to show the tooptip on each line. I have tried this

var series = new Series
                    {
                        Name = chartPoint.SetName,
                        Color = chartPoint.ChartColor,
                        ChartType = SeriesChartType.Line,
                        BorderDashStyle = chartPoint.ChartDashStyle,
                        BorderWidth = chartPoint.BorderWidth,
                        IsVisibleInLegend = !chartPoint.HideLegend,
                        ToolTip = "Hello World"
                    };

but its not working for me

like image 517
Ravi Mittal Avatar asked May 30 '26 03:05

Ravi Mittal


1 Answers

You have two options either use Keywords accepted by the Chart control.

myChart.Series[0].ToolTip = "Name #SERIESNAME : X - #VALX{F2} , Y - #VALY{F2}";

In the Chart control, a Keyword is a character sequence that is replaced with an automatically calculated value at run time. For a comprehensive list of keywords accepted by the Chart control look up Keyword reference or

if you want something more fanciful, you have to handle the event GetToolTipText

this.myChart.GetToolTipText += new System.Windows.Forms.DataVisualization.Charting.Chart.ToolTipEventHandler(this.myChart_GetToolTipText);

Now I am not sure what you want to show on the ToolTip but you could add the logic accordingly. Assuming you want to show the values of the DataPoints in the series

private void myChart_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
{
    switch(e.HitTestResult.ChartElementType)
    {  
        case ChartElementType.DataPoint:
            e.Text = myChart.Series[0].Points[e.HitTestResult.PointIndex]).ToString()
                     + /* something for which no keyword exists */;
            break;
        case ChartElementType.Axis:
            // add logic here
        case ....
        .
        .    
        default:
            // do nothing       
    }
like image 66
Joe Vi Avatar answered May 31 '26 17:05

Joe Vi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!