wpf toolkit chart rotate axis

2020-04-20 09:16发布

问题:

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.

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

Thank you again.

回答1:

This post explains how to rotate the labels in a manner that works for both WPF and Silverlight

http://blogs.msdn.com/b/delay/archive/2010/03/06/turn-your-head-and-check-out-this-post-how-to-easily-rotate-the-axis-labels-of-a-silverlight-wpf-toolkit-chart.aspx

becomes



回答2:

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>


回答3:

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.