隐藏具有多个数据系列的WPF工具包图表的图例 [英] Hide legend of WPF Toolkit chart with more than one data series
问题描述
我想使用WPF工具包(使用LineSeries)的图表,我不想要一个图例。我需要这个,因为我有10这样的图表,每个来自不同的来源的数据,我想画一个传说为所有10,以节省屏幕的房地产。
I am trying to use charts from the WPF Toolkit (with LineSeries) and I don't want a legend at all. I need this since I have 10 such charts each with data from a different source and I would like to draw one legend for all 10, to save screen real estate.
默认图例出现在您添加第二个LineSeries的时刻。是否有任何方法阻止它出现?
By default the legend appears the moment you add a second LineSeries. Is there any way to prevent it from even appearing?
谢谢,
精灵。
推荐答案
似乎没有一个特别干净的方式。一个简单的方法是使用LegendStyle将Legend的Width设置为零:
There doesn't seem to be an especially clean way. One simple approach is to set the Legend's Width to zero using LegendStyle:
<charting:Chart>
<charting:Chart.LegendStyle>
<Style TargetType="datavis:Legend">
<Setter Property="Width" Value="0" />
</Style>
</charting:Chart.LegendStyle>
更激烈的方法是将ControlTemplate替换为不包含图例的: >
A more drastic approach is to replace the ControlTemplate with one that does not include a Legend:
<charting:Chart>
<charting:Chart.Template>
<ControlTemplate TargetType="{x:Type charting:Chart}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" />
<chartingprimitives:EdgePanel Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" Grid.Row="1" Margin="0,15,0,15">
<Grid Panel.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Panel.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
</chartingprimitives:EdgePanel>
</Grid>
</Border>
</ControlTemplate>
</charting:Chart.Template>
使用以下命名空间:
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
这篇关于隐藏具有多个数据系列的WPF工具包图表的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!