Tooltip not showing on VB.NET chart Series set by Databinding

278 views Asked by At

Using VB.NET 4.8.04161. I have a chart that I create from a DataTable, and I'd like to display a tooltip on hover with the Y-Value. I'm setting the tooltip for each series as a whole using the "#VALY" variable. But nothing appears when I hover. To test, I've also added a tooltip to the legend of each series with dummy text, and that also does not show up. Finally I added a tooltip to a Button on the same form as the chart and that works just fine.

I've also looked through the few questions on SO relating to missing tooltips - all were on setting tooltips to specific datapoints, not the series as a whole. One suggested increasing the dp size (How to display tooltips with various data in MS charts and WinForm Chart not showing ToolTip), which seemed to work for the OP. So I increased BorderWidth to 20 (from 3) with no luck.

I also paused execution to make sure that Chart1.series(0).Tooltip had a value. My code is below:

            Dim dt as DataTable = <Getting a datatable from a SQL query>
            Chart1.ChartAreas(0).AxisX.IntervalType = DateTimeIntervalType.Months
            Chart1.ChartAreas(0).AxisX.Interval = 1
            Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = -45
            Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "c0"
            ToolTip1.ShowAlways = True  'Addded to see if it would help-it did not
            For Each ser As DataColumn In dt.Columns
                If ser.ColumnName <> "DateMonth" Then
                    Dim s As New Series
                    Dim mp As String = ser.ColumnName
                    s.Name = mp
                    s.ChartType = SeriesChartType.Line
                    s.BorderWidth = 3
                    s.Points.DataBindXY(dt.Rows, "DateMonth", dt.Rows, mp)
                    s.ToolTip = "#VALY"
                    s.LegendToolTip = "THis isthe legend"
                    Chart1.Series.Add(s)
                End If
            Next
            For Each legend In Chart1.Legends
                legend.Docking = Docking.Bottom
                legend.Alignment = StringAlignment.Center
            Next

What am I missing for why the tooltip doesn't show on a chart element but works on a form control?

1

There are 1 answers

2
JorisJ1 On

I am unable to reproduce your issue in a vb.net 4.8 Windows Forms App.

As a substitute for the datasource I added some dummy data:

Dim dt As New DataTable()
dt.Columns.Add(New DataColumn("DateMonth", Type.GetType("System.DateTime")))
dt.Columns.Add(New DataColumn("Column2", Type.GetType("System.Int32")))

'Add dummy data points, one random integer Y-value per month.
Dim random As New Random
For index = 1 To 10
    Dim row1 As DataRow
    row1 = dt.NewRow()
    row1.Item(0) = New DateTime(2022, 1, 1).AddMonths(index)
    row1.Item(1) = random.Next(1, 10)
    dt.Rows.Add(row1)
Next

When running the application the tooltips seem to work fine. enter image description here

Would you please test with this same dummy data, and/or show some code that better emulates your own dataset?