c# - 工具包图表旋转标签 X 轴

标签 c# .net silverlight charts silverlight-toolkit

首先感谢您阅读本文。

我有以下问题:
我希望我的 X 轴 te 的标签旋转 90 度。使文本面向垂直而不是水平。我的 X 轴是自动生成的,但并非必须如此。 使标签的内容是垂直的而不是水平的。我已经尝试了多种选择来实现这一点,但还没有一个对我有用。所以我真的希望任何人都知道如何让它发挥作用。使用我尝试过的选项,只有另一个轴只显示数字。虽然我想要的是要转动的标签,以便所有文本都适合轴而不相互重叠。

下图是现在的样子: How it is right now.

这是我希望它成为的示例(这是在 excel 中制作的): The way i would like it to be.

我浏览了更多网站,但找不到适合我的网站。
无论是在 xaml 中还是在后面的代码中都适合我。
这是我现在使用的代码:

<toolkit:Chart Margin="8,72,0,8" Title="Aantal meldingen per afdeling" x:Name="chartMeldingenPerAfdeling">
        <toolkit:Chart.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="White" Offset="0"/>
                <GradientStop Color="#FF476D88" Offset="1"/>
            </LinearGradientBrush>
        </toolkit:Chart.Background>
        <toolkit:ColumnSeries ItemsSource="{Binding}" DependentValuePath="AantalMeldingen"
                               IndependentValuePath="Afdeling" Margin="0,0,0,1" 
                           Title="Aantal meldingen" Padding="0" VerticalContentAlignment="Center" 
                           HorizontalContentAlignment="Center" FontSize="8"/>
        <toolkit:LineSeries ItemsSource="{Binding}" DependentValueBinding="{Binding Percentage}" DependentRangeAxis="{Binding ElementName=PercentageAxis}"
                            IndependentValueBinding="{Binding Afdeling}" IndependentAxis="{Binding ElementName=lin}" Title="Pareto"/>
        <toolkit:Chart.Axes>
            <toolkit:LinearAxis Orientation="Y" Location="Left" Title="Aantal" x:Name="AantalAxis"/>
            <toolkit:LinearAxis Orientation="Y" Location="Right" Title="Percentage" x:Name="PercentageAxis" Minimum="0" Maximum="100"/>
        </toolkit:Chart.Axes>
    </toolkit:Chart>

提前谢谢你。

最佳答案

请检查这段代码:

<toolkit:Chart Title="{Binding ChartTitle}" x:Name="myChart" Style="{StaticResource myChartStyle}" BorderBrush="{x:Null}"  Background="Black" Foreground="White">
            <toolkit:ColumnSeries ItemsSource="{Binding LegendList}"
                DependentValueBinding="{Binding FeatureQuantity}" 
                IndependentValueBinding="{Binding LegendName}" DataPointStyle="{Binding Source={StaticResource ColorByGradeColumn}}" >

            </toolkit:ColumnSeries>

            <toolkit:Chart.Axes>
                <toolkit:CategoryAxis Orientation="X" 
                                      Location="Bottom" 
                                      Foreground="White">
                    <toolkit:CategoryAxis.AxisLabelStyle>
                        <Style TargetType="toolkit:AxisLabel">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate 
                                          TargetType="toolkit:AxisLabel">
                                        <TextBlock 
                                 Text="{TemplateBinding FormattedContent}" 
                                                   TextAlignment="Right" 
                                                   TextWrapping="Wrap" 
                                                   Width="60" 
                                                   Margin="-20,15,0,0" 
                                                   RenderTransformOrigin="0.5,0.5">
                                            <TextBlock.RenderTransform>
                                                <RotateTransform Angle="90" />
                                            </TextBlock.RenderTransform>
                                        </TextBlock>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </toolkit:CategoryAxis.AxisLabelStyle>
                </toolkit:CategoryAxis>
            </toolkit:Chart.Axes>

        </toolkit:Chart>

结果是: http://upload7.ir/imgs/2014-10/42094080161295718077.png

关于c# - 工具包图表旋转标签 X 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26055658/

相关文章:

silverlight - 在 XAML (Silverlight, WP) 的一个地方为网格中的所有文本 block 设置前景色

WPF 到 Silverlight 项目转换

c# - 将 SQL 转换为具有多个表和组的 LINQ

c# - 在启动时显示自定义错误页面

.net - 在 .NET 中实现属性过滤器

c# - .NET Winforms 应用程序中的报告

.net - 记录 WP7 的事件信息?

c# - 如何在没有 AAD 访问权限的 Microsoft 团队聊天机器人中实现用户身份验证?

c# - 导致 Socket.Receive 返回的最小字节数是多少?

c# - 文件系统路径和 Directory.Exists()