wpf toolkit chart rotate axis

2020-04-20 09:01发布

How do you rotate the text in the axis from horizontal to vertical?

I cant do it through xaml because I am a creating multiple series on the fly and I do not know up front how many I will have until after the control populates.

enter image description here

I need to display the dates vertical or at a slant and not horz.

Thank you again.

3条回答
狗以群分
2楼-- · 2020-04-20 09:37

Maybe, that will help:
http://community.devexpress.com/blogs/bryan/archive/2011/01/19/silverlight-and-wpf-charts-changing-the-axis-label-angles.aspx
I know, it's in xaml, but i don't think there is another way, wpf charting is by far not so comfortable like windows forms charting (where you can easily rotate the labels via property).
For your needs you might to write the style into a resource and reference it in your code-behind.

查看更多
地球回转人心会变
3楼-- · 2020-04-20 09:58

Not sure if you have found the answer for this, but on the off-chance that you haven't you can try the following:

This is in XAML, but should work no matter how many series' you create as it is styling the axis.

        <chart:Chart.Axes>
            <chart:DateTimeAxis Orientation="X" ShowGridLines="True">
                <chart:DateTimeAxis.AxisLabelStyle>
                    <Style TargetType="{x:Type chart:AxisLabel}">
                        <Setter Property="StringFormat" Value="{}{0:d-MMM}" />
                        <Setter Property="RenderTransformOrigin" Value="1,0.5" />
                        <Setter Property="RenderTransform">
                            <Setter.Value>
                                <RotateTransform Angle="-45" />
                            </Setter.Value>
                        </Setter>
                    </Style>
                </chart:DateTimeAxis.AxisLabelStyle>
            </chart:DateTimeAxis>

            <chart:LinearAxis ShowGridLines="True" />
        </chart:Chart.Axes>
查看更多
太酷不给撩
4楼-- · 2020-04-20 09:59
登录 后发表回答