I am programmatically adding series to my XamDataChart; these data come from the server and hence I can't put them in xaml since I wouldn't know how many series I will get back.
When I tried to add tooltip using a tooltip template I kept getting: 'ToolTip' cannot have a logical or visual parent. Same problem when I tried to wrap this in a markertemplate instead.
Other than this the series display fine. Can you advise?
My code:
private void AddSpreads(SomeDataCollection panelVMs) { SpreadChart.Series.Clear(); var toolTipTemplate = SpreadChart.Resources["ToolTipTemplate"] as DataTemplate; for (int i = 0; i < panelVMs.Count; i++) { RolledATMVolPanelViewModel panelVM = panelVMs[i]; string pair = panelVM.CcyPair;
// add to spreads chart var series = new ScatterLineSeries { Title = pair, MarkerType = MarkerType.Circle, Brush = CommonSettings.Colours[i % CommonSettings.Colours.Length], XAxis = XAxis, YAxis = YAxis, XMemberPath = "DaysToMaturity", YMemberPath = "Spread", }; series.MarkerBrush = series.MarkerOutline = series.Brush; if (toolTipTemplate != null) { var toolTip = new ToolTip(); toolTip.ContentTemplate = toolTipTemplate; series.ToolTip = toolTip; }
var spreads = new List<SpreadItem>();//... here I populate spreads with data from teh view model
series.ItemsSource = spreads; SpreadChart.Series.Add(series); } }
My xaml:
<Controls:XamDock Margin="0"> <Charts:XamDataChart Controls:XamDock.Edge="Central" Margin="3" Legend="{Binding ElementName=Legend}" VerticalZoomable="True" VerticalZoombarVisibility="Collapsed" Background="Transparent" HorizontalZoomable="True" HorizontalZoombarVisibility="Collapsed" Name="SpreadChart"> <Charts:XamDataChart.Resources> <DataTemplate x:Key="ToolTipTemplate"> <StackPanel Orientation="Vertical"> <StackPanel> <TextBlock FontWeight="Bold" Text="{Binding Series.Title}"/> </StackPanel> <StackPanel> <TextBlock FontWeight="Bold" Text="Mty: "/> <TextBlock Text="{Binding Item.DaysToMaturity}"/> </StackPanel> <StackPanel> <TextBlock FontWeight="Bold" Text="Spread: "/> <TextBlock Text="{Binding Item.Spread, StringFormat=0.00%}"/> </StackPanel> </StackPanel> </DataTemplate> </Charts:XamDataChart.Resources> <Charts:XamDataChart.Axes> <Charts:NumericXAxis x:Name="XAxis" Label="{}{:0}" MajorStroke="Transparent" MinorStroke="Transparent" IsLogarithmic="True" LogarithmBase="10" > <Charts:NumericXAxis.LabelSettings> <Charts:AxisLabelSettings Location="OutsideBottom" Extent="35" /> </Charts:NumericXAxis.LabelSettings> </Charts:NumericXAxis>
<Charts:NumericYAxis x:Name="YAxis" Label="{}{:0.00%}" > <Charts:NumericYAxis.LabelSettings > <Charts:AxisLabelSettings Location="OutsideLeft" Extent="55" /> </Charts:NumericYAxis.LabelSettings> </Charts:NumericYAxis> </Charts:XamDataChart.Axes> </Charts:XamDataChart>
<Charts:Legend Name="Legend" Controls:XamDock.Edge="InsideTop" Controls:XamDock.VerticalDockAlignment="Top" Controls:XamDock.HorizontalDockAlignment="Right"/> </Controls:XamDock>
Hello,
I added my tooltip in the code as exactly same as you mentioned above.
But when I point mouse to the top of lineseries I got "cannot create a top-level child window".
But after a few times getting that error, It starts to show tooltip.
I am really stuck on that error for 5-6 months.
Waiting for your help
Thanks
Thanks!
All works now
ContentControl.ContentProperty rather. Sorry, relying on head compiler for the moment.
try adding:
tooltip.SetBinding(ContentProperty, new Binding());
Thanks Graham; it does show up now.
However the data binding doesn't work - it just shows as blank (except the static texts). Something wrong with my template/code settings?