直方图将柱状图替换为面积图,优化密集数据显示效果,Y轴刻度自动取整支持 K/M 缩写,X 轴根据数据范围自动设置。

This commit is contained in:
QI Mingxuan
2026-05-21 10:37:28 +08:00
parent ef83a7637a
commit d7c027b732
3 changed files with 131 additions and 20 deletions
@@ -0,0 +1,49 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace XP.Common.Controls.ImageHistogram
{
/// <summary>
/// 频次标签转换器:将大数值转为 K/M 缩写格式 | Frequency label converter: converts large values to K/M abbreviation format
/// 例如:500000 → "500K"1500000 → "1.5M"800 → "800"
/// </summary>
internal sealed class FrequencyLabelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return "0";
double num;
if (value is double d)
num = d;
else if (value is decimal dec)
num = (double)dec;
else if (!double.TryParse(value.ToString(), out num))
return value.ToString() ?? "0";
if (num >= 1_000_000)
{
double mValue = num / 1_000_000.0;
return mValue == Math.Floor(mValue)
? $"{(int)mValue}M"
: $"{mValue:0.#}M";
}
if (num >= 1_000)
{
double kValue = num / 1_000.0;
return kValue == Math.Floor(kValue)
? $"{(int)kValue}K"
: $"{kValue:0.#}K";
}
return $"{(int)num}";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}