From 2d981530890ee86ae462c7dd925b58ded6993dd8 Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 25 Oct 2024 10:44:56 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIBarChart:=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=BF=AB=E6=8D=B7=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=87=BD=E6=95=B0ShowData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Charts/UIBarChart.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/SunnyUI/Charts/UIBarChart.cs b/SunnyUI/Charts/UIBarChart.cs index fc19b120..818ad060 100644 --- a/SunnyUI/Charts/UIBarChart.cs +++ b/SunnyUI/Charts/UIBarChart.cs @@ -31,7 +31,8 @@ * 2023-05-13: V3.3.6 Option.BarInterval,设置Bar之间间隔,默认-1,自动计算间隔 * 2023-05-14: V3.3.6 重构DrawString函数 * 2023-06-06: V3.3.7 修复Y轴文字居中 - * 2025-06-08: V3.6.6 修复X轴文字带角度显示时居中 + * 2024-06-08: V3.6.6 修复X轴文字带角度显示时居中 + * 2024-10-25: V3.7.2 增加了一个快捷的显示数据函数ShowData ******************************************************************************/ using System; @@ -646,5 +647,23 @@ namespace Sunny.UI public UIBarSeries Series { get; set; } } + + public void ShowData(string[] labels, double[] values, string title = "") + { + int len = Math.Min(labels.Length, values.Length); + if (len == 0) return; + + UIBarOption option = new UIBarOption(); + option.Title.Text = title; + var series = new UIBarSeries(); + for (int i = 0; i < len; i++) + { + option.XAxis.Data.Add(labels[i]); + series.AddData(values[i]); + } + + option.Series.Add(series); + SetOption(option); + } } } \ No newline at end of file