Hello,
Can someone share code snippet on activating tooltip value when user hovers on a scatter point of the scatter series?
I have built scatter series in the code behind and all I want to add is the ability to see the values (both X and Y) when user hovers it.
Hi Priyank,
The scatter series has a ToolTip property which you can set to some FrameworkElement that you want to use to represent your tooltip. Since you are creating the series in code behind, an easy way to handle this is to create a DataTemplate in your XAML that defines what your tooltip will look like. Then in code behind you can call DataTemplate.LoadContent() in order to instantiate this tooltip content. Ex:
XAML:
<DataTemplate x:Key="ToolTipTemplate"> <Grid> <TextBlock Text="{Binding Item.ValueProperty}"/> </Grid></DataTemplate>
Code behind:
var series = new ScatterSeries();series.ItemsSource = mydata;series.XMemberPath = "X";series.YMemberPath = "Y";series.XAxis = xAxis;series.YAxis = yAxis;
var dt = Resources["ToolTipTemplate"] as DataTemplate;series.ToolTip = dt.LoadContent();
Thanks Rob!
I see the tooltip window showing up as I hover to a scatter point but somehow the binding is messing it up and I cant see the value. I am doing data binding in the code behind too as
series.Title = model.SelectVar1;
How can I modify the above code to capture this data binding?
Thanks!
If the value is not appearing then the binding is probably not correct. You can confirm this by checking the Visual Studio output window. If there is a binding error while you are debugging it will appear there.
What does your tooltip binding look like? If it looks like the binding in my DataTemplate snippet above then as long as you replaced the ValueProperty with the name of the property you want to use in your data point class then it should work. Just to clarify things I attached a sample that creates a ScatterSeries in code behind and applies a tooltip.
Were you able to get the tooltip working?
Right. There was that option as well. If that works for you then that is probably the best way to meet your requirement. It's unfortunate that the custom tooltip didn't work for you. If you'd like, please modify the sample I attached previously to reproduce your issue so I can see why it doesn't work.
Hello Rob,
I used the series.defaulttooltip = True instead and now I can see the X,Y values.
Somehow the binding method as you suggested did not work.
Cheers,
Priyank