wpf toolkit chart rotate axis

大憨熊 提交于 2019-12-02 10:04:38

问题


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.



来源:https://stackoverflow.com/questions/4870202/wpf-toolkit-chart-rotate-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!