Custom Label

3 posts, 0 answers
  1. Jesus
    Jesus avatar
    4 posts
    Member since:
    Nov 2013

    Posted 26 Apr 2015 Link to this post

    Hi,

    This is my code in xaml ...

     

    <chart:RadCartesianChart  x:Name="Chart" Grid.Row="1"
                               PaletteName="DefaultLight"
                               Margin="20,0,20,20"
                               HorizontalAlignment="Stretch" 
                               VerticalAlignment="Stretch">
                               <chart:RadCartesianChart.Grid>
                                   <chart:CartesianChartGrid
                                       MajorLinesVisibility="XY">
                                       <chart:CartesianChartGrid.MajorYLineStyle>
                                           <Style TargetType="Line">
                                               <Setter Property="Stroke" Value="#DDDDDD"/>
                                           </Style>
                                       </chart:CartesianChartGrid.MajorYLineStyle>
                                       <chart:CartesianChartGrid.MajorXLineStyle>
                                           <Style TargetType="Line">
                                               <Setter Property="Stroke" Value="#DDDDDD"/>
                                           </Style>
                                       </chart:CartesianChartGrid.MajorXLineStyle>
                                   </chart:CartesianChartGrid >
                               </chart:RadCartesianChart.Grid>
                               <chart:RadCartesianChart.HorizontalAxis>
                                   <chart:CategoricalAxis
                                       PlotMode="BetweenTicks"
                                       TickThickness="0"
                                       Foreground="Black">
     
                                       <chart:CategoricalAxis.LineStyle>
                                           <Style TargetType="Line">
                                               <Setter Property="Stroke" Value="#545454"/>
                                           </Style>
                                       </chart:CategoricalAxis.LineStyle>
                                   </chart:CategoricalAxis>
                               </chart:RadCartesianChart.HorizontalAxis>
                               <chart:RadCartesianChart.VerticalAxis>
                                   <chart:LinearAxis
                                       Foreground="Black">
                                       <chart:LinearAxis.LineStyle>
                                           <Style TargetType="Line">
                                               <Setter Property="Stroke" Value="#545454"/>
                                           </Style>
                                       </chart:LinearAxis.LineStyle>
                                   </chart:LinearAxis>
                               </chart:RadCartesianChart.VerticalAxis>                          
                               <chart:RadCartesianChart.SeriesProvider>
                                   <chart:ChartSeriesProvider
                                       Source="{Binding ModelChart}">
                                       <chart:ChartSeriesProvider.SeriesDescriptors>
                                           <chart:CategoricalSeriesDescriptor
                                               ItemsSourcePath="Data"
                                               ValuePath="Value"
                                               CategoryPath="Category"
                                               LegendTitlePath="Name">
                                               <chart:CategoricalSeriesDescriptor.Style>
                                                   <Style TargetType="chart:SplineSeries">
                                                       <Setter Property="CombineMode" Value="None"/>
                                                       <Setter Property="ShowLabels" Value="True"/>
                                                       <Setter Property="PointTemplate" Value="{StaticResource PoinTemplate}"/>
                                                   </Style>
                                               </chart:CategoricalSeriesDescriptor.Style>
                                           </chart:CategoricalSeriesDescriptor>
                                       </chart:ChartSeriesProvider.SeriesDescriptors>
                                   </chart:ChartSeriesProvider>
                               </chart:RadCartesianChart.SeriesProvider>
                           </chart:RadCartesianChart>

    Note that ...

     

    <Setter Property="ShowLabels" Value="True"/>

     

    How can I custom my Labels???

    I've seen something in the documentation, but not it and include it in the code....

     

    <chart:LineSeries.LabelDefinitions>
                                                    <chart:ChartSeriesLabelDefinition>
                                                        <chart:ChartSeriesLabelDefinition.Template>
                                                            <DataTemplate>
                                                                <TextBlock Text="{Binding Value}" Foreground="White" />
                                                            </DataTemplate>
                                                        </chart:ChartSeriesLabelDefinition.Template>
                                                    </chart:ChartSeriesLabelDefinition>
                                                </chart:LineSeries.LabelDefinitions>

    Also I would like to format currency, how I do it?

    Thanks

     

  2. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 30 Apr 2015 Link to this post

    Hello,

    The Series' labels can be customized through Label Definitions. However the Series.LabelDefinitions property does not have a setter and therefore it cannot be set through a style. For this reason, the ChartSeriesDescriptor(in this case the CategoricalSeriesDescriptor) exposes an entry point where you can modify the series as per your needs. You can override its CreateInstanceCore method and get the generated series. For example:

    public class CustomDescriptor : CategoricalSeriesDescriptor
    {
        protected override ChartSeries CreateInstanceCore(object context)
        {
            var series = base.CreateInstanceCore(context);

                 //customize the series
            //series.LabelDefinitions.Add(new ChartSeriesLabelDefinition(){ .....});
     
            return series ;
        }
    }

    I hope this helps.

    Regards,
    Ivaylo Gergov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Jesus
    Jesus avatar
    4 posts
    Member since:
    Nov 2013

    Posted 04 May 2015 in reply to Ivaylo Gergov Link to this post

    Thanks .... Work it!!!!
Back to Top