You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除WPF Toolkit Charting Control中的图表图例?

移除WPF Toolkit Charting Control图例的方法

嘿,我之前也跟你一样被这个问题困扰过!要去掉图表旁边那个红圈标注的图例,其实有几种简单直接的办法,给你详细说说:

方法一:在XAML中直接隐藏(最推荐)

你可以直接在<charting:Chart>标签里设置LegendVisibility属性为Collapsed,这样就能一键隐藏图例:

<charting:Chart 
    Title="你的图表标题"
    LegendVisibility="Collapsed">
    <!-- 你的系列数据 -->
</charting:Chart>

如果这个属性没生效(可能是版本差异),你也可以手动找到Chart内部的Legend控件,直接设置它的可见性:

<charting:Chart Title="你的图表标题">
    <charting:Chart.Legend>
        <charting:Legend Visibility="Collapsed" />
    </charting:Chart.Legend>
    <!-- 你的系列数据 -->
</charting:Chart>

方法二:通过后台代码控制

要是你需要动态控制图例的显示/隐藏,也可以在C#代码里找到Chart的Legend控件并设置它的可见性:

// 假设你的Chart控件名为myChart
var legend = myChart.Template.FindName("Legend", myChart) as Legend;
if (legend != null)
{
    legend.Visibility = Visibility.Collapsed;
}

或者更直接一点,直接设置Chart的LegendVisibility属性:

myChart.LegendVisibility = Visibility.Collapsed;

我当时试下来第一种XAML的方法最省心,直接在布局里搞定,不用写额外的代码。你可以根据自己的场景选合适的方式~

内容的提问来源于stack exchange,提问作者Chan Joshua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:58:21