How to set chart Axis Appearance.Foreground?

9 posts, 1 answers
  1. Iurie Coroban
    Iurie Coroban avatar
    32 posts
    Member since:
    Jan 2004

    Posted 29 Apr 2009 Link to this post

    By default foreground is White, I want to set it to Black color. How can I do this?
    for BarSeris I found

    barSeries.Definition.Appearance.Foreground= new SolidColorBrush(Colors.Black);

  2. Answer
    Ves
    Admin
    Ves avatar
    2926 posts

    Posted 30 Apr 2009 Link to this post

    Hi Iurie,

    You can take advantage of the AxisXStyle property of the ChartArea. Define your own style in XAML and populate this property, here is an example:

    <UserControl x:Class="SilverlightApplication1.Page" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        Width="400" Height="300" 
        xmlns:control="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting" 
        xmlns:chart="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
     
        <Grid x:Name="LayoutRoot"
            <Grid.Resources> 
                <Style x:Name="MyAxisXStyle" TargetType="chart:AxisX2D"
                    <Setter Property="Foreground" Value="Red" /> 
                    <Setter Property="LineStroke" Value="Green" /> 
                </Style> 
            </Grid.Resources> 
            <control:RadChart x:Name="RadChart1" > 
            </control:RadChart> 
        </Grid> 
    </UserControl> 
     

    and in code-behind:

    using System.Windows; 
    using System.Windows.Controls; 
     
    namespace SilverlightApplication1 
        public partial class Page : UserControl 
        { 
            public Page() 
            { 
                InitializeComponent(); 
                this.Loaded += new RoutedEventHandler(Page_Loaded); 
            } 
     
            void Page_Loaded(object sender, RoutedEventArgs e) 
            { 
                RadChart1.ItemsSource = new double[] { 1, 2, 3, 4 }; 
                RadChart1.DefaultView.ChartArea.AxisXStyle = this.MyAxisXStyle; 
            } 
        } 

    Hope this helps.

    Regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Iurie Coroban
    Iurie Coroban avatar
    32 posts
    Member since:
    Jan 2004

    Posted 30 Apr 2009 Link to this post

    Thanks for example, it helps me.
  4. Ian
    Ian avatar
    51 posts
    Member since:
    Apr 2009

    Posted 29 May 2009 Link to this post

    The code sample shows the TargetType of the style being AxisX2D but there is no such target in the Charting namespace and the code shown gives a XAML error that the target source cannot be found

    What am I missing here?

    Ian
  5. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 01 Jun 2009 Link to this post

    Hello Ian,

    Here is the list of references you need:
    • Telerik.Windows.Data
    • Telerik.Windows.Controls
    • Telerik.Windows.Controls.Charting
    And these are the xml namespace mappings needed:
    • xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
    •  xmlns:chart="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"

    As soon as you have these in place, you should not get such error.

    Sincerely,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Ian
    Ian avatar
    51 posts
    Member since:
    Apr 2009

    Posted 01 Jun 2009 Link to this post

    Thanks Ves. That's got me sorted :-) I had the references and the declarations in the XAML but since the Knowledgebase article made no mention of the Telerik.Windows.Data component being needed in the code behind to resolve the reference in the XAML I was missing the required using statement for Telerik.Windows.Data

    It's probably worth updating the Knowledgebase article here: http://www.telerik.com/support/kb/silverlight/chart/customize-the-axis-appearance.aspx so that others don't fall foul of the same problem.

    Thanks again.
  7. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 02 Jun 2009 Link to this post

    Hello Ian,

    Sorry for the confusion and thanks for the note. We'll have our KB articles updated.

    Regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Ken
    Ken avatar
    8 posts
    Member since:
    Jun 2009

    Posted 28 Aug 2009 Link to this post

    I'm using the telerik controls for Silvelight 3.0.  I'm finding this example - I get a runtime xaml parse exception with the message "Invalid "attribute value LineStroke for property Property."  Inspecting the Axis2D class, I find no LineStroke property, but do find Stroke.  This works for me:

    <Setter Property="Stroke" Value="Black"/>

    Another issue on the knowledge base page - the "If you'd like to comment on this KB article, please, send us a Support Ticket." - the "Support Ticket" link is broken.

    Thanks!
  9. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 01 Sep 2009 Link to this post

    Hi Ken,

    Thanks for the note. Indeed, it is the Stroke property that should be used. We have updated the article.

    As for the "Support Ticket" link - it is expected to point to this location and it appears to work fine for me now.The link you have copied here also seems to work. Please, give it another try and let us know if the problem remains.

    I have updated your Telerik points.

    Sincerely,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top