TooltipTemplate for LineSeries

3 posts, 0 answers
  1. Magnus
    Magnus avatar
    2 posts
    Member since:
    Nov 2016

    Posted 25 Nov 2016 Link to this post

    I am trying to show a ToolTipTemplate for LineSeries but don't get it to work.

    If I try with Bar series instead it works just fine.

    Code in xaml.cs file

            private CartesianSeries CreateLineSeries(List<GraphPointDto> items, Brush brush)
            {
                var series = new LineSeries()
                {
                    ItemsSource = items,
                    Stroke = brush,
                    ValueBinding = new PropertyNameDataPointBinding("Value"),
                    CategoryBinding = new PropertyNameDataPointBinding("DateTime"),
                    TooltipTemplate = this.Resources["MyToolTipTemplate"] as DataTemplate,
                };
                return series;
            }

     

     

     

    Code in xaml

     

  2. Tanya
    Admin
    Tanya avatar
    469 posts

    Posted 29 Nov 2016 Link to this post

    Hello Magnus,

    To show a tooltip on a LineSeries, you should define the template of the data points using the PointTemplate property. This is because the tooltip is shown for the data points of a series, which are missing in the visualization of a LineSeries. More information on the matter is available in the ToolTip help article.

    With the latest versions of RadChartView, you can use the DefaultVisualStyle property of the series instead of the approach described above. All you need to do to enable the tooltip is to define Width, Height and Fill for the style. The benefit of this approach is that you will have much smaller number of visual elements generated and your application will need fewer resources.

    Hope this helps.

    Regards,
    Tanya
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  3. Magnus
    Magnus avatar
    2 posts
    Member since:
    Nov 2016

    Posted 01 Dec 2016 in reply to Tanya Link to this post

    Yes, thank you very much, now it works just like I want it to.

    private CartesianSeries CreateLineSeries(List<GraphObisValue> items, Brush brush, string obisName)
            {
                var style = new Style(typeof(System.Windows.Shapes.Path));
                style.Setters.Add(new Setter(WidthProperty, 2.0));
                style.Setters.Add(new Setter(HeightProperty, 2.0));
                style.Setters.Add(new Setter(System.Windows.Shapes.Path.FillProperty, brush));
                var series = new LineSeries()
                {
                    ItemsSource = items,
                    Stroke = brush,
                    ValueBinding = new PropertyNameDataPointBinding("ValueAsDecimal"),
                    CategoryBinding = new PropertyNameDataPointBinding("GraphTimeStamp"),               
                    TooltipTemplate = this.Resources["MyToolTipTemplate"] as DataTemplate,
                    DefaultVisualStyle = style,               
                    LegendSettings = new SeriesLegendSettings { Title = obisName },               
                };
                return series;
            }

Back to Top