Jacob
Jacob

Reputation: 346

How to make Live Charts DataTooltip only show current hover?

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;

Upvotes: 4

Views: 4534

Answers (1)

Sharku
Sharku

Reputation: 1092

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

Upvotes: 5

Related Questions