使用多个数据系列隐藏 WPF Toolkit 图表的图例 [英] Hide legend of WPF Toolkit chart with more than one data series

查看:24
本文介绍了使用多个数据系列隐藏 WPF Toolkit 图表的图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 将图例的宽度设置为零:

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>

一种更激进的方法是用不包含 Legend 的 ControlTemplate 替换 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 Toolkit 图表的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆