Custom smart labels

8 posts, 0 answers
  1. Lee
    Lee avatar
    5 posts
    Member since:
    Mar 2014

    Posted 24 Apr 2014 Link to this post

    I want to change color of smart label.

    but I don't find example...

    please help me...
  2. Markus
    Markus avatar
    42 posts
    Member since:
    Nov 2012

    Posted 24 Apr 2014 Link to this post

    Hi,
    Smart Labels

    also in the Wpf examples:
    ChartView -> SmartLabels

    Regards Markus
  3. Lee
    Lee avatar
    30 posts
    Member since:
    Apr 2014

    Posted 24 Apr 2014 in reply to Markus Link to this post

    Thank you for reply.

    This example is automatic form.

    My 'RadCartesianChart' is created in 'Black Label Color'

    I want to change this color.
  4. Martin
    Admin
    Martin avatar
    1226 posts

    Posted 29 Apr 2014 Link to this post

    Hello Lee,

    Keep in mind that the smart labels are actually normal labels with a positioning strategy applied. The SmartLabels strategy is positioning the labels in such a way so they do not overlap one another. In order to customize the appearance of the labels of the chart's series you can define a LabelDefinition. Then you can change the color of the labels by setting the Foreground property of the element inside the template of the definition.
    <telerik:LineSeries ShowLabels="True">
        <telerik:LineSeries.LabelDefinitions>
            <telerik:ChartSeriesLabelDefinition>
                <telerik:ChartSeriesLabelDefinition.Template>
                    <DataTemplate>
                        <TextBlock Text="{Binding Value}" Foreground="White" />
                    </DataTemplate>
                </telerik:ChartSeriesLabelDefinition.Template>
            </telerik:ChartSeriesLabelDefinition>
        </telerik:LineSeries.LabelDefinitions>
    </telerik:LineSeries>

    Regards,
    Martin
    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.
     
  5. Lee
    Lee avatar
    5 posts
    Member since:
    Mar 2014

    Posted 29 Apr 2014 in reply to Martin Link to this post

    Thank you for your reply.

    Additionally, I want to work in code-behind(Converter Class).

    My converter is below that.

    NumericalAxis verticalAxis = null;
    LinearAxis axis = new LinearAxis();

    axis.Foreground = new SolidColorBrush(Colors.White);
    axis.FontSize = 11;

    verticalAxis = axis;

    return verticalAxis;
  6. Martin
    Admin
    Martin avatar
    1226 posts

    Posted 30 Apr 2014 Link to this post

    Hi Lee,

    In order to set the color of the labels of the axis you can use the LabelStyle property of the axis. As for the changing of the foreground color of the series labels there is another approach slightly different than this I suggested in my last reply. Instead of defining template for the LabelDefinition you can set its DefaultVisualStyle property. You can use the following style (or similar) for both properties (LabelStyle and DefaultVisualStyle):

    <Window.Resources>
        <Style x:Key="labelStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="Green" />
        </Style>
    </Window.Resources>
    To create a definition and set the styles in code-behind you can use the following code:

    // Get the style
    Style labelStyle = (Style)this.Resources["labelStyle"];
    // Create new labelDefinition and set its DefaultVisualStyle property
    ChartSeriesLabelDefinition labelDefinition = new ChartSeriesLabelDefinition() { DefaultVisualStyle = labelStyle };
     
    // add the label definition in the LabelDefinitions collection of your series
    myLineSeries.LabelDefinitions.Add(labelDefinition);
    // set the style for the labels of the axis
    axis.LabelStyle = labelStyle;

    Please let me know if this information helps.

    Regards,
    Martin
    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.
     
  7. karthikeyan
    karthikeyan avatar
    1 posts
    Member since:
    Jan 2016

    Posted 02 Mar in reply to Lee Link to this post

    Hi Lee,

            I want to add labelformat to vertical axis with display value as percentages can you help me out

    Thanks,

    Karthik

  8. Martin
    Admin
    Martin avatar
    1226 posts

    Posted 06 Mar Link to this post

    Hello Karthik,

    You can try the LabelFormat or LabelTemplate properties of the axis. 

    Regards,
    Martin
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top