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

3D Axis Label Styling

1 Answer 26 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Richard Alvarez
Top achievements
Rank 1
Richard Alvarez asked on 28 Apr 2011, 07:34 PM
I'm trying to style the axis labels, in accordance with the code here (http://www.telerik.com/help/silverlight/radchart-styling-and-appearance-styling-axis-item-label.html), but without a xaml style reference.  In my code-behind, I have this...

Style style = new Style(typeof(TextBlock));
style.Setters.Add(new Setter(TextBlock.FontSizeProperty, 5));
chart.DefaultView.ChartArea.AxisX.AxisStyles.ItemLabelStyle = style;

But, it's not doing anything to the appearance.  This is for a 3D line chart.  Do I need a different type in the setter?

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 04 May 2011, 09:01 AM
Hello Richard Alvarez,

Styling 3D charts is a little bit different than styling 2D. 3D charts use different templates, styles and controls. Currently styling a 3D series type can be done by using implicit styles or setting the style directly on the element from code behind.

First create your style with target type Label3D (this is the type for 3D labels) like this:

private Style CreateStyle()
{
    Style style = new Style(typeof(Label3D));
    style.Setters.Add(new Setter(Label3D.FontSizeProperty, 5));
    return style;
}

Next hook up to the ChartArea Loaded event and apply the style to the axis labels like this:
public SilverlightControl12()
{
    InitializeComponent();
 
    this.ProductChart.DefaultView.ChartArea.Loaded += new RoutedEventHandler(ChartArea_Loaded);
     
    ....
}
void ChartArea_Loaded(object sender, RoutedEventArgs e)
{
    ChartArea area = sender as ChartArea;
    var axisLabels = area.ChildrenOfType<LayoutTransformControl>();
    Style style = CreateStyle();
    foreach (var item in axisLabels)
    {
        item.FindChildByType<Label3D>().Style = style;
    }
}

Axis labels are wrapped in LayoutTransformControl because they can be rotated. This separates them from the series item labels that are added only as Label3D objects. Feel free to modify the code above as you please.

Hope this helps!


Kind regards,
Yavor Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Richard Alvarez
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or