PointTemplate in Chart with SeriesDescriptor

3 posts, 0 answers
  1. Daniel
    Daniel avatar
    7 posts
    Member since:
    Feb 2013

    Posted 27 Jun 2014 Link to this post

    Hi, How can I set a PointTemplate to chart series, series are defined using SeriesDescriptor.
    My goal is to show tooltips in each point of the series
    I have tried the following but is not working
    Thanks for your help.
    <Grid.Resources>
                  <DataTemplate x:Key="PointDataTemplate">
                    <Ellipse Width="6" Height="6" />
                </DataTemplate>
    </Grid.Resources>

    <telerik:RadCartesianChart x:Name="MonitoringParameterChart" >
               <telerik:RadCartesianChart.Behaviors>
                   <telerik:ChartTooltipBehavior HorizontalOffset="-17" VerticalOffset="-70"/>
               </telerik:RadCartesianChart.Behaviors>
               <telerik:RadCartesianChart.TooltipTemplate>
                   <DataTemplate>
                       <Grid>
                           <Path Data="M-1236,-441 L-1208,-441 L-1208,-424 L-1228,-424 L-1230.5,-420 L-1233,-424 L-1236,-424 z"
                                           Stretch="Fill" Fill="#FFFFFFFF" Stroke="#FF767676" StrokeThickness="1" />
                           <TextBlock Margin="6,4,6,10" FontSize="11">
                                               <Run Text="{Binding Value, StringFormat=\{0:#########\}}"/>
                                               <LineBreak/>
                                               <Run Text="{Binding Category, StringFormat=\{0:dd MMM yyyy\}}"/>
                           </TextBlock>
                       </Grid>
                   </DataTemplate>
               </telerik:RadCartesianChart.TooltipTemplate>
               <telerik:RadCartesianChart.SeriesProvider>
                   <telerik:ChartSeriesProvider x:Name="MonitoringParametersSeriesProvider" Source="{Binding}">
                       <telerik:ChartSeriesProvider.SeriesDescriptors >
                           <telerik:CategoricalSeriesDescriptor ItemsSourcePath="Values" ValuePath="Value" CategoryPath="Time" >
                               <telerik:CategoricalSeriesDescriptor.Style>
                                   <Style TargetType="telerik:LineSeries">
                                       <Setter Property="StrokeThickness" Value="1"/>
                                        <Setter Property="PointTemplate" Value="{StaticResource PointDataTemplate}" />
                                   </Style>
                               </telerik:CategoricalSeriesDescriptor.Style>
                           </telerik:CategoricalSeriesDescriptor>
                       </telerik:ChartSeriesProvider.SeriesDescriptors>
                   </telerik:ChartSeriesProvider>
               </telerik:RadCartesianChart.SeriesProvider>
     
           </telerik:RadCartesianChart>
  2. Daniel
    Daniel avatar
    7 posts
    Member since:
    Feb 2013

    Posted 30 Jun 2014 in reply to Daniel Link to this post

    I found a thread that gave me the solution:
    <Setter Property="PointTemplate" ><BR> <Setter.Value><BR>
    <DataTemplate><BR> <Ellipse Width="6" Height="6" Fill="{Binding
    Converter={StaticResource paletteConverter}}"/><BR> </DataTemplate><BR>
    </Setter.Value><BR> </Setter>
    public class PaletteConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                CategoricalDataPoint point = value as CategoricalDataPoint;
                LineSeries series = point.Presenter as LineSeries;
                RadCartesianChart chart = series.Chart as RadCartesianChart;
                int seriesIndex = chart.Series.IndexOf(series);
                return chart.Palette.GlobalEntries[seriesIndex].Fill;
            }
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
               throw new NotImplementedException();
            }
     
        }

    The only troblue is that I have more series than color in the palette.
  3. DevCraft banner
  4. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 01 Jul 2014 Link to this post

    Hello Daniel,

    I am happy to hear that you have found an approach that achieves your requirement for custom PointTemplate. Regarding the number of the colors in a palette, if you need to extend the palette (to add more colors) you can take a look at the Creating Custom palettes article. Following it, you will be able to define custom colors that will be used to paint your series. This will allow you to control the number of the series with different colors.

    Regards,
    Pavel R. Pavlov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top