1

我遇到了 LiveCharts:PieMenu 的问题。我在资源文件上定义了 PieChart 和 PieSeries 的样式,以便我所有的饼图看起来都一样。在 UserControl 中,我使用资源字典中的资源文件并将其添加到资源中,然后创建 2 个饼图:

    <Border HorizontalAlignment="Stretch"
            Background="{StaticResource MenuBackgroundScb2}" 
            BorderThickness="2" BorderBrush="{StaticResource WidgetBorderScb}"
            Margin="0 0 0 20">
        <StackPanel HorizontalAlignment="Stretch" >
            <Label Content="Montant des offres selon leurs états" Style="{StaticResource TitleLabel}"/>
            <lc:PieChart Series="{Binding Path=AmountOfferByStatusSeriesCollection}"/>
        </StackPanel>
    </Border>
    <Border HorizontalAlignment="Stretch"
            Background="{StaticResource MenuBackgroundScb2}" 
            BorderThickness="2" BorderBrush="{StaticResource WidgetBorderScb}">
        <StackPanel HorizontalAlignment="Stretch" >
            <Label Content="Nombre d'offres selon leurs états" Style="{StaticResource TitleLabel}"/>
            <lc:PieChart Series="{Binding Path=NbOfferByStatusSeriesCollection}"  />
        </StackPanel>
    </Border>

第一个图表饼图看起来不错,但第二个饼图有问题:图例未显示,鼠标悬停会使应用程序崩溃。

漏洞

该错误出现是因为我在单独的资源文件中而不是在 PieChart 的资源中声明了样式,所以我知道 Series NbOfferByStatusSeriesCollection 没有问题。

此外,我有第三个饼图,它显示在另一个页面中,与前两个不同,而且这个饼图工作正常。

我做错了什么??

这是资源文件的摘录。

<Style TargetType="lc:PieChart">
    <Setter Property="Height" Value="140"/>
    <Setter Property="InnerRadius" Value="25"/>
    <Setter Property="SeriesColors" Value="{StaticResource GraphColors}" />
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="LegendLocation" Value="Right" />
    <Setter Property="ChartLegend">
        <Setter.Value>
            <lc:DefaultLegend BulletSize="20"/>
        </Setter.Value>
    </Setter>
    <Setter Property="DataTooltip">
        <Setter.Value>
            <lc:DefaultTooltip SelectionMode="OnlySender" 
                                       Foreground="{StaticResource LightForegroundScb}"
                                       Background="{StaticResource MenuBackgroundScb2}" 
                                       BorderThickness="2"
                                       BorderBrush="{StaticResource MenuBackgroundScb}"
                                       BulletSize="20" />
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="lc:PieSeries">
    <Setter Property="Stroke" Value="{StaticResource MenuBackgroundScb2}"/>
    <Setter Property="StrokeThickness" Value="3"/>
</Style>

这是调用堆栈:

在此处输入图像描述

4

1 回答 1

1

原来我必须在饼图样式之外设置默认图例和默认 dataTooltip 的样式,并将它们添加到饼图样式资源中:

<Style TargetType="lc:DefaultLegend" x:Key="PieChartDefaultLegend">
    <Setter Property="BulletSize" Value="20"/>
</Style>

<Style TargetType="lc:DefaultTooltip" x:Key="PieChartDefaultTooltip">
    <Setter Property="SelectionMode" Value="OnlySender"/>
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="Background" Value="{StaticResource MenuBackgroundScb2}" />
    <Setter Property="BorderThickness" Value="2"/>
    <Setter Property="BorderBrush" Value="{StaticResource MenuBackgroundScb}"/>
    <Setter Property="BulletSize" Value="20" />
</Style>

<Style TargetType="lc:PieChart">
    <Setter Property="InnerRadius" Value="25"/>
    <Setter Property="SeriesColors" Value="{StaticResource GraphColors}" />
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="LegendLocation" Value="Right" />
    <Style.Resources>
        <Style BasedOn="{StaticResource PieChartDefaultLegend}" TargetType="lc:DefaultLegend"/>
        <Style BasedOn="{StaticResource PieChartDefaultTooltip}" TargetType="lc:DefaultTooltip"/>
    </Style.Resources>
</Style>
于 2017-10-18T18:38:07.537 回答