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

RadChart tooltip: e.DataPoint.DataItem is always null

2 Answers 109 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jeroen
Top achievements
Rank 1
Jeroen asked on 19 Apr 2012, 03:44 PM
In the following chart...

<telerik:RadChart telerik:StyleManager.Theme="Expression_Dark"
                                              HorizontalAlignment="Left"
                                              Name="ChartJam"
                                              VerticalAlignment="Stretch"
                                              PaletteBrushesUseSolidColors="True"
                                              Loaded="ChartJam_Loaded"
                                                   Height="Auto" MinHeight="100"
                                                   Width="Auto" MinWidth="200"
                                          Margin="0" BorderThickness="0"
                                                   Cursor="Hand">
                        <telerik:RadChart.DefaultView>
                            <telerik:ChartDefaultView>
                                <telerik:ChartDefaultView.ChartArea>
                                    <telerik:ChartArea EnableAnimations="False" x:Name="MyChartArea"
                                                               ItemToolTipOpening="ChartArea_ItemToolTipOpening">
                                        <telerik:ChartArea.AxisY >
                                            <telerik:AxisY Title="" AutoRange="True"
                                                               StripLinesVisibility="Visible" MajorGridLinesVisibility="Visible">
                                            </telerik:AxisY>
                                        </telerik:ChartArea.AxisY>
                                        <telerik:ChartArea.Annotations>
                                        </telerik:ChartArea.Annotations>
                                        <telerik:ChartArea.AxisX>
                                            <telerik:AxisX IsDateTime="True"
                                                               MajorGridLinesVisibility="Visible" MinorGridLinesVisibility="Visible"
                                                               Title=""
                                                               LabelRotationAngle="45"
                                                               DefaultLabelFormat="HH:mm"
                                                               AutoRange="True"
                                                               LabelStep="1"
                                                               TicksDistance="20">                                                             
                                            </telerik:AxisX>
                                        </telerik:ChartArea.AxisX>
                                    </telerik:ChartArea>
                                </telerik:ChartDefaultView.ChartArea>                              
                            </telerik:ChartDefaultView>
                        </telerik:RadChart.DefaultView>
                    </telerik:RadChart>

ChartJam.DefaultView.ChartArea.AxisX.AxisStyles.ItemLabelStyle = App.Current.Resources["ChartLabel"] as Style;          
            ChartJam.DefaultView.ChartArea.AxisY.AxisStyles.ItemLabelStyle = App.Current.Resources["ChartLabel"] as Style;
  
            ChartJam.DefaultView.ChartArea.Annotations.Clear();
            ChartJam.DefaultView.ChartArea.EnableAnimations = false;
  
            ChartJam.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;
            ChartJam.DefaultSeriesDefinition = new AreaSeriesDefinition()
            {
                Appearance = new SeriesAppearanceSettings()
                {
                    Stroke = Utilities.StringToSolidColorBrush("93D427"),
                    StrokeThickness = 1.0,
                    Fill = new SolidColorBrush(Colors.Black)
                },
                ShowPointMarks = false,
                ShowItemLabels = false,
                ShowItemToolTips = true
            };
  
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.ItemMappings.Add(new ItemMapping("JamLength", DataPointMember.YValue));
            seriesMapping.ItemMappings.Add(new ItemMapping("DtJamLength", DataPointMember.XValue));
  
            ChartJam.SeriesMappings.Add(seriesMapping);
  
            ChartJam.ItemsSource = _chartsJamGuardVM.LineData;
              
            _chartsJamGuardVM.DownloadChartJam();

... in the ItemToolTipOpening event, the e.DataPoint.DataItem is always null.

private void ChartArea_ItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
        {
            if (e.DataPoint.DataItem == null)
            {
                tooltip.Content = null;
                return;
            }
...

Any ideas why?

2 Answers, 1 is accepted

Sort by
0
Jeroen
Top achievements
Rank 1
answered on 19 Apr 2012, 04:38 PM
The tooltips work fine if I reduce the amount of points in the chart... A chart with 1000 points doesn't work, while 200 points is fine. What am I doing wrong?
0
Petar Marchev
Telerik team
answered on 24 Apr 2012, 12:37 PM
Hi Jeroen,

This is the result of the Sampling feature of the chart. Here you can read about it. In short it is a data sampling mechanism that clusters (summarizes) few data items into a single data point. For instance, if you have 4000 data item in the items source, and if the SamplingThreshold is 200 (by default it is 200) - the chart will get populated with 200 data points, each holding information for 20 data items.

This feature is on by default (with SamplingThreshold=200). It is on by default because of performance considerations. One option you have is to turn off the sampling by setting the threshold to zero.

I would generally suggest that you keep the sampling on and explore the sampling functions (from the link above). The custom sampling functions should allow you to specify the text in the tooltip while keeping the sampling enabled.

I have attached a simple app to get you started with the custom sampling functions. Note that this is a wpf project, but all the code should be valid for Silverlight.

All the best,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Jeroen
Top achievements
Rank 1
Answers by
Jeroen
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or