4

I have a pie chart using Live Charts in a winform and I've tried using the code in the documentation to change the tool tip to just the current hover:

pieChart1.DataTooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender;

However I get the following error: Severity Code Description Project File Line Suppression State

'UserControl' does not contain a definition for 'SelectionMode' and no accessible extension method 'SelectionMode' accepting a first argument of type 'UserControl' could be found (are you missing a using directive or an assembly reference?)

I am not sure what I am missing? The code below is what I am using to draw the piechart.

Func<ChartPoint, string> labelPoint = chartPoint =>
            string.Format("${0:n}", chartPoint.Y, chartPoint.Participation);

        SeriesCollection series = new SeriesCollection();
        //reads in a data table and creates a pie series for each data row
        foreach (DataRow dr in dt.Rows)
        {
            PieSeries ps = new PieSeries
            {
                Title = dr["Name"].ToString(),
                Values = new ChartValues<double> {
                            double.Parse(dr["Budget Amount"].ToString())},
                DataLabels = true,
                LabelPoint = labelPoint

            };

            series.Add(ps);
        }

        pieChart1.Series = series;          
        pieChart1.LegendLocation = LegendLocation.Bottom;
        pieChart1.DataTooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender;
Jacob
  • 346
  • 3
  • 13

1 Answers1

5

DataTooltip can be any WPF UserControl. So to change the SelectionMode you need to cast it to a DefaultTooltip.

var tooltip = (LiveCharts.DefaultTooltip) pieChart1.DataTooltip
tooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender
Sharku
  • 1,052
  • 1
  • 11
  • 24
  • This is in a winform so I am not sure how to do what you are saying. – Jacob Dec 10 '19 at 19:18
  • @Jacob I added some code, to make my answer clearer. – Sharku Dec 11 '19 at 10:29
  • Thank you! Made a lot more sense. – Jacob Dec 11 '19 at 16:35
  • 1
    In windows form, I was getting error on "LiveCharts.DefaultToolTip". Following code worked fine for me var tooltip = (DefaultTooltip)PieChartPriorityDisplay.DataTooltip; tooltip.SelectionMode = TooltipSelectionMode.OnlySender; – Kg7 Jan 19 '23 at 04:31