This is a migrated thread and some comments may be shown as answers.

TooltipTemplate for LineSeries

2 Answers 207 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Magnus
Top achievements
Rank 1
Magnus asked on 25 Nov 2016, 09:38 AM

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 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 29 Nov 2016, 03:58 PM
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, 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.
0
Magnus
Top achievements
Rank 1
answered on 01 Dec 2016, 07:48 AM

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;
        }

Tags
ChartView
Asked by
Magnus
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Magnus
Top achievements
Rank 1
Share this question
or