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

Custom Label

2 Answers 88 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jesús
Top achievements
Rank 1
Jesús asked on 26 Apr 2015, 03:49 PM

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

Sort by
0
Ivaylo Gergov
Telerik team
answered on 30 Apr 2015, 08:15 AM
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.

 
0
Jesús
Top achievements
Rank 1
answered on 04 May 2015, 02:17 PM
Thanks .... Work it!!!!
Tags
Chart
Asked by
Jesús
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Jesús
Top achievements
Rank 1
Share this question
or