From 6c41b71eccd0db5b7b2625e0456b9181e6c13a94 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 15 Jan 2020 19:49:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`AxisLabel`=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E4=B8=BA=E6=95=B4=E6=95=B0=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation/XCharts配置项手册.md | 2 +- Runtime/Component/Sub/AxisLabel.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index f2581de0..c0b4cbf2 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -630,7 +630,7 @@ * `color`:刻度标签文字的颜色,默认取主题Theme的axisTextColor。 * `fontSize`:文字的字体大小。 * `fontStyle`:文字字体的风格。 -* `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value},{value:f1} 表示取1为小数 +* `formatter`:图例内容字符串模版格式器。支持用 \n 换行。模板变量为图例名称 {value},支持{value:f0},{value:f1},{value:f2}。 * `forceENotation`:是否强制使用科学计数法格式化显示数值。默认为false,当小数精度大于3时才采用科学计数法。 ## `AxisLine` diff --git a/Runtime/Component/Sub/AxisLabel.cs b/Runtime/Component/Sub/AxisLabel.cs index e01941ee..6df65d69 100644 --- a/Runtime/Component/Sub/AxisLabel.cs +++ b/Runtime/Component/Sub/AxisLabel.cs @@ -71,7 +71,7 @@ namespace XCharts public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } } /// /// 图例内容字符串模版格式器。支持用 \n 换行。 - /// 模板变量为图例名称 {value},{value:f1} 表示取1为小数 + /// 模板变量为图例名称 {value},支持{value:f0},{value:f1},{value:f2} /// public string formatter { get { return m_Formatter; } set { m_Formatter = value; } } /// @@ -173,6 +173,8 @@ namespace XCharts else if (m_Formatter.Contains("{value")) { var content = m_Formatter; + if (content.Contains("{value:f0}")) + content = m_Formatter.Replace("{value:f0}", ChartCached.IntToStr((int)value)); if (content.Contains("{value:f2}")) content = m_Formatter.Replace("{value:f2}", ChartCached.FloatToStr(value, 2)); else if (content.Contains("{value:f1}")) @@ -180,7 +182,6 @@ namespace XCharts else if (content.Contains("{value}")) { if (value - (int)value == 0) - content = m_Formatter.Replace("{value}", ChartCached.IntToStr((int)value)); else content = m_Formatter.Replace("{value}", ChartCached.FloatToStr(value, 1));