如何在wpf工具包lineseries图表中为每个单独的数据点定制工具提示?(How to customize a tooltip for each individual datapoint in a

编程入门 行业动态 更新时间:2024-10-10 03:30:58
如何在wpf工具包lineseries图表中为每个单独的数据点定制工具提示?(How to customize a tooltip for each individual datapoint in a wpf toolkit lineseries chart?)

我已经看到几个关于为单行系列做自定义工具提示的问题。

我需要为每个数据点提供自定义工具提示。 我想在工具提示中添加更多内容,而不仅仅是依赖值路径和独立值路径。

示例I在同一行上有2个数据点,其中值(Y轴)为2,日期(x轴)为2016年4月28日,配置为A.另一个值为3,日期为2016年4月29日,配置B.

我怎么还显示配置? 这都是在代码背后完成的,因为我有一个动态数量的lineseries。 所以我不能只为xaml中的每个lineseries分配一个样式。

var MyLineSeries = new LineSeries(); lMyLineSeries.DependentValuePath = "Y"; lMyLineSeries.IndependentValuePath = "X"; lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;

这是我创建工具提示样式的代码。

var lToolTipDataPointStyle = new Style(typeof(LineDataPoint)); var lTemplate = new ControlTemplate(typeof(LineDataPoint)); var lGridElement = new FrameworkElementFactory(typeof(Border)); //Tooltip var lStackPanel = new StackPanel(); var lValueContentControl = new ContentControl(); lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath)); lValueContentControl.ContentStringFormat = "Value: {0}"; var lConfigurationContentControl = new ContentControl(); lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to??? lConfigurationContentControl.ContentStringFormat = "Configuration: {0}"; lStackPanel.Children.Add(lValueContentControl); lStackPanel.Children.Add(lConfigurationContentControl); lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel); var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse)); lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty)); lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty)); lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty)); lGridElement.AppendChild(lEllipseElement); lTemplate.VisualTree = lGridElement; var lTemplateSetter = new Setter(); lTemplateSetter.Property = LineDataPoint.TemplateProperty; lTemplateSetter.Value = lTemplate; lToolTipDataPointStyle.Setters.Add(lTemplateSetter); return lToolTipDataPointStyle;

I have seen several questions about doing a custom tooltip for a single line series.

I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.

Example I have 2 data points on the same line one with a value(Y-axis) of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has a value of 3, date of 4/29/2016, and configuration of B.

How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.

var MyLineSeries = new LineSeries(); lMyLineSeries.DependentValuePath = "Y"; lMyLineSeries.IndependentValuePath = "X"; lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;

This is my code for creating the tool tip style.

var lToolTipDataPointStyle = new Style(typeof(LineDataPoint)); var lTemplate = new ControlTemplate(typeof(LineDataPoint)); var lGridElement = new FrameworkElementFactory(typeof(Border)); //Tooltip var lStackPanel = new StackPanel(); var lValueContentControl = new ContentControl(); lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath)); lValueContentControl.ContentStringFormat = "Value: {0}"; var lConfigurationContentControl = new ContentControl(); lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to??? lConfigurationContentControl.ContentStringFormat = "Configuration: {0}"; lStackPanel.Children.Add(lValueContentControl); lStackPanel.Children.Add(lConfigurationContentControl); lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel); var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse)); lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty)); lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty)); lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty)); lGridElement.AppendChild(lEllipseElement); lTemplate.VisualTree = lGridElement; var lTemplateSetter = new Setter(); lTemplateSetter.Property = LineDataPoint.TemplateProperty; lTemplateSetter.Value = lTemplate; lToolTipDataPointStyle.Setters.Add(lTemplateSetter); return lToolTipDataPointStyle;

最满意答案

我通过使用Line on the Line系列来解决这个问题。

myLineSeries.Tag = "Configuration"; var lConfigurationContentControl = new ContentControl(); lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString())) lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

I figured it out by using the Tag on the Line series.

myLineSeries.Tag = "Configuration"; var lConfigurationContentControl = new ContentControl(); lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString())) lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

更多推荐

new,var,lToolTipDataPointStyle,电脑培训,计算机培训,IT培训"/> <meta name=&quo

本文发布于:2023-07-27 02:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具包   据点   图表   中为   提示

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!