【问题标题】:Show legend item into two column将图例项显示为两列
【发布时间】:2018-03-13 01:39:49
【问题描述】:

我正在使用 WpfToolkit 绘制饼图,由于我的图例太多,我喜欢将我的图例显示为两列,我该如何解决?

<chartingToolkit:Chart Height="auto" x:Name="PieChart2" Title="{Binding}"  
        VerticalAlignment="Top" Grid.Row="0" Grid.ColumnSpan="3" Margin="5" LegendTitle="Label" >
            <chartingToolkit:PieSeries DependentValuePath="Value"
        IndependentValuePath="Key" ItemsSource="{Binding}">
            </chartingToolkit:PieSeries>
            <charting:Chart.LegendStyle>
                <Style TargetType="datavis:Legend">
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                </Style>
            </charting:Chart.LegendStyle>
        </chartingToolkit:Chart>

提前致谢!

【问题讨论】:

  • 但是为什么在图例中提供了默认滚动查看器时需要两列
  • @VishalPrajapati 抱歉让您感到困惑,我需要将数据打印成 pdf 并且该功能不允许提供的滚动查看器,所以我必须在不显示滚动查看器的情况下显示所有图例。

标签: wpf data-visualization wpftoolkit


【解决方案1】:

根据您的需要,我稍微更改了图例的 ControlTemplate,如下所示

  <ControlTemplate x:Key="LegendControlTemplate1"
                     TargetType="{x:Type visualizationToolkit:Legend}">
        <Border BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Background="{TemplateBinding Background}"
                Padding="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <visualizationToolkit:Title x:Name="HeaderContent"
                                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                                            Content="{TemplateBinding Header}"
                                            Grid.Row="0"
                                            Style="{TemplateBinding TitleStyle}" />
                <ScrollViewer BorderThickness="0"
                              IsTabStop="False"
                              Padding="0"
                              Grid.Row="1"
                              VerticalScrollBarVisibility="Auto">
                    <!--<ItemsPresenter  x:Name="Items"
                                    Margin="10,0,10,10" >
                    </ItemsPresenter>-->
                    <ItemsControl x:Name="Items"
                                  Margin="10,0,10,10"
                                  ItemsSource="{TemplateBinding ItemsSource}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="2" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>

                </ScrollViewer>
            </Grid>
        </Border>
    </ControlTemplate>

我不确定这是否符合您的要求。如果满意,请将其标记为答案。

【讨论】:

    猜你喜欢
    • 2014-11-30
    • 1970-01-01
    • 2021-12-17
    • 2019-04-01
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    • 2017-05-01
    • 2012-09-02
    相关资源
    最近更新 更多