aligning categorical style over more than one series

5 posts, 0 answers
  1. Steven
    Steven avatar
    22 posts
    Member since:
    May 2011

    Posted 21 Sep 2012 Link to this post

    Is there a sensible way to align the category that a series is plotted against for charts that are kept inside a StackPanel?

    Currently the only two chart types that have been tried which do not line up are OHLC and line.

    I would post a snapshot if I could work out how via your forum.
  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 26 Sep 2012 Link to this post

    Hello Steven,

    You can align 2 charts horizontally by making their Y-axis the same size. One way of doing this is by applying a label style that sets the width of the labels to a predefined one. Here is some code:

    <Style x:Key="labelStyle" TargetType="TextBlock">
        <Setter Property="Width" Value="42" />
        <Setter Property="TextAlignment" Value="Right" />
        <Setter Property="Margin" Value="0,0,3,0" />
    </Style>

    Here is how you can apply it:
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis LabelStyle="{StaticResource labelStyle}" />
    </telerik:RadCartesianChart.VerticalAxis>

    I have attached a sample project that demonstrates this approach.All the best,
    Yavor
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. DevCraft banner
  4. Steven
    Steven avatar
    22 posts
    Member since:
    May 2011

    Posted 27 Sep 2012 Link to this post

    That example you posted works.  I was attempting to do this afterwards:

    var xaml = @"
    <RadCartesianChart xmlns=""http://schemas.telerik.com/2008/xaml/presentation"">
        <RadCartesianChart.VerticalAxis>
            <LinearAxis LabelStyle=""{StaticResource labelStyle}"" />
        </RadCartesianChart.VerticalAxis>
    </RadCartesianChart>
    ";
     
                var chart = System.Windows.Markup.XamlReader.Load(xaml) as RadCartesianChart;
    
    Any ideas on how I should configure the xmlns?  It is saying that it doesn't understand the StaticResource
  5. Steven
    Steven avatar
    22 posts
    Member since:
    May 2011

    Posted 27 Sep 2012 Link to this post

    thanks for your example.  I integrated these ideas into my code, and I still can't get the categories to line up.  i.e. one chart has open high low close, the other has a simple line plot.  It just doesn't line up.

  6. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 02 Oct 2012 Link to this post

    Hi Steven,

    You need to add also these xaml namespaces:


    Here is how your definition should look like in order for the xaml parser to properly read it:
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" />

    As I mentioned in my previous reply, in order for your horizontal axes align you have to be sure, that the vertical axes have the same ActualWidth. If everything else is the same (ticks length, axis thickness, title), then the only thing different are the labels. Setting a label style that gives them a constant width will make both of the vertical axes the same size.

    I have attached a modified version of my previous test app that shows a line and OHLC series that have aligned horizontal axes.

    Greetings,
    Yavor
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner