We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Tooltip with custom text for SfChart series

I want each point in my series to show a tooltip with some custom text when my mouse hovers over it. The tooltip should be something like "IdNumber, Xvalue, Yvalue". I have no problem getting the X and Y values to show but I don't know how to bind some identification number IdNumber for each point. Please help.


This is what I have now
=============================================

// New up the series and add to chart

var series = new FastScatterBitmapSeries();

chart.Series.Add(series);

// Series Data Binding

series.ItemsSource = plotPoints;

series.XBindingPath = "X";

series.YBindingPath = "Y";

series.ScatterHeight = 4;

series.ScatterWidth = 4;

// Series Tooltips

series.ShowTooltip = true;

var template = new DataTemplate();

var txtblock = new FrameworkElementFactory(typeof(TextBlock));

txtblock.SetValue(TextBlock.WidthProperty, 85.0);

txtblock.SetValue(TextBlock.HeightProperty, 25.0);

txtblock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);

txtblock.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);

txtblock.SetValue(TextBlock.FontSizeProperty, 15.0);

var binding = new Binding();

binding.Path = new PropertyPath("ToolTip"); // This works for YData but how do I bind it to a custom ToolTip text

txtblock.SetValue(TextBlock.TextProperty, binding);

FrameworkElementFactory grid = new FrameworkElementFactory(typeof(StackPanel));

grid.AppendChild(txtblock);

template.VisualTree = grid;

series.TooltipTemplate = template;

=============================================



This is my PlotPoint class that has a custom tooltip text for each X,Y point


=============================================

private class PlotPoint




{



public PlotPoint(double x, double y, string toolTip=null)




{



X = x;


Y = y;


ToolTip = toolTip;




}



public double X { get; set; }


public double Y { get; set; }


public string ToolTip { get; set; }




}

=============================================







3 Replies

DA Devi Aruna Maharasi Murugan Syncfusion Team March 16, 2017 12:03 PM UTC

Hi Keenan, 
  
Thanks for contacting Syncfusion Support. 
  
Since we can get the corresponding data model value from the tooltip’s datacontext as Item, we are able to bind any of the model property in tooltip as shown in the below code snippet, 
 
Model.CS 
 
public class Model 
    { 
        public double XValue { get; set; } 
        public double YValue { get; set; } 
        public string IDNum { get; set; } 
    } 
 
 
Tooltip text Binding 
 
  var binding = new Binding(); 
 
  binding.Path = new PropertyPath("Item.IDNum"); //corresponding model of the fast     
                                                   scatter as Item 
 
  txtblock.SetValue(TextBlock.TextProperty, binding); 
  
We have prepared the demo sample based on the provided code snippet and it can be downloaded from below link, 
Sample: CustomTooltip 
  
Please find the output screenshot, 
 
Regards, 
Devi 






LL llllllllll March 16, 2017 03:31 PM UTC

Thank you that worked!


DA Devi Aruna Maharasi Murugan Syncfusion Team March 17, 2017 03:28 AM UTC

Hi Keenan, 
  
Thanks for your update. 
  
Please let us know, if you need any further assistance on this. 
  
Regards, 
Devi 


Loader.
Up arrow icon