diff --git a/Documentation~/en/api.md b/Documentation~/en/api.md
index 61e710e5..1655f477 100644
--- a/Documentation~/en/api.md
+++ b/Documentation~/en/api.md
@@ -1031,7 +1031,11 @@ A candlestick chart is a style of financial chart used to describe price movemen
|GetSerieLabelName()||public static string GetSerieLabelName(string prefix, int i, int j)|
|GetString()||public static string GetString(string prefix, int suffix)|
|IntToStr()||public static string IntToStr(int value, string numericFormatter = "")|
+|NumberToDateStr()||public static string NumberToDateStr(double timestamp, string formatter)|
+|NumberToDateTime()||public static DateTime NumberToDateTime(double timestamp)|
|NumberToStr()||public static string NumberToStr(double value, string formatter)|
+|NumberToTimeSpan()||public static TimeSpan NumberToTimeSpan(double timestamp)|
+|NumberToTimeStr()||public static string NumberToTimeStr(double timestamp, string formatter)|
## ChartConst
@@ -1361,12 +1365,13 @@ DataZoom component is used for zooming a specific area, which enables user to in
|public method|since|description|
|--|--|--|
-|GetDateTime()||public static DateTime GetDateTime(double timestamp)|
-|GetDateTime()||public static DateTime GetDateTime(int timestamp)|
+|GetDateTime()||public static DateTime GetDateTime(double timestamp, bool local = true)|
|GetDefaultDateTimeString()||public static string GetDefaultDateTimeString(int timestamp, double range = 0)|
|GetTimestamp()||public static int GetTimestamp()|
-|GetTimestamp()||public static int GetTimestamp(DateTime time)|
-|GetTimestamp()||public static int GetTimestamp(string dateTime)|
+|GetTimestamp()||public static int GetTimestamp(DateTime time, bool local = false)|
+|GetTimestamp()||public static int GetTimestamp(string dateTime, bool local = false)|
+|IsDateOrTimeRegex()||public static bool IsDateOrTimeRegex(string regex)|
+|IsDateOrTimeRegex()||public static bool IsDateOrTimeRegex(string regex, ref bool date, ref string formatter)|
## DebugInfo
diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md
index 12ed0d9e..630ba945 100644
--- a/Documentation~/en/configuration.md
+++ b/Documentation~/en/configuration.md
@@ -1259,7 +1259,7 @@ The interface for serie data component.
|opacity|1||透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
|itemMarker|||提示框单项的字符标志。用在Tooltip中。
|itemFormatter|||提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter`
-|numericFormatter|||Standard numeric format strings.
+|numericFormatter|||Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
Date format: Starts with `date`, which is used to format DateTime. Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are: d day, HH hour, mm minute, ss second, fffffff fractional part. Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped. For example: time:HH\:mm\:ss
number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
Note: The date and time formats are only supported by 'v3.12.0' or later.
|cornerRadius|||The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
```mdx-code-block
@@ -1320,7 +1320,7 @@ Text label of chart, to explain some data information about graphic item like va
|autoRotate|false|v3.6.0|auto rotate of label.
|distance|||the distance of label to axis line.
|formatter|||label content string template formatter. \n line wrapping is supported. Formatters for some components will not take effect.
Template placeholder have the following, some of which apply only to fixed components:
`{.}` : indicates the dot mark.
`{a}` : indicates the series name.
`{b}` : category value of x axis or data name.
`{c}` : data value.
`{d}` : percentage.
`{e}` : indicates the data name.
`{f}` : data sum.
`{g}` : indicates the total number of data.
`{h}` : hexadecimal color value.
`{y}` : category value of y axis.
`{value}` : The value of the axis or legend.
The following placeholder apply to `UITable` components:
`{name}` : indicates the row name of the table.
`{index}` : indicates the row number of the table.
The following placeholder apply to `UIStatistc` components:
`{title}` : title text.
`{dd}` : day.
`{hh}` : hours.
`{mm}` : minutes.
`{ss}` : second.
`{fff}` : milliseconds.
`{d}` : day.
`{h}` : hours.
`{m}` : minutes.
`{s}` : second.
`{f}` : milliseconds.
Example :{b}:{c}
-|numericFormatter|||Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
Date format Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: yyyy-MM-dd HH:mm:ss
number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+|numericFormatter|||Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
Date format: Starts with `date`, which is used to format DateTime. Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are: d day, HH hour, mm minute, ss second, fffffff fractional part. Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped. For example: time:HH\:mm\:ss
number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
Note: The date and time formats are only supported by 'v3.12.0' or later.
|width|0||the width of label. If set as default value 0, it means than the label width auto set as the text width.
|height|0||the height of label. If set as default value 0, it means than the label height auto set as the text height.
|icon|||the sytle of icon. [IconStyle](#iconstyle)|
@@ -1813,6 +1813,19 @@ Radial axis of polar coordinate.
> class in XCharts.Runtime / Inherits from: [Serie](#serie)
+```mdx-code-block
+
+```
+
+
+|field|default|since|comment|
+|--|--|--|--|
+|radiusGradient|false|v3.12.0|Whether to use gradient color in pie chart.
+
+```mdx-code-block
+
+```
+
## Scatter
> class in XCharts.Runtime / Inherits from: [BaseScatter](#basescatter)
@@ -2350,7 +2363,7 @@ Tooltip component.
|fixedHeight|0||Fixed height. Higher priority than minHeight.
|minWidth|0||Minimum width. If fixedWidth has a value, get fixedWidth first.
|minHeight|0||Minimum height. If fixedHeight has a value, take priority over fixedHeight.
-|numericFormatter|||Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
Date format Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: yyyy-MM-dd HH:mm:ss
number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+|numericFormatter|||Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
Date format: Starts with `date`, which is used to format DateTime. Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are: d day, HH hour, mm minute, ss second, fffffff fractional part. Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped. For example: time:HH\:mm\:ss
number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
Note: The date and time formats are only supported by 'v3.12.0' or later.
|paddingLeftRight|10||the text padding of left and right. defaut:5.
|paddingTopBottom|10||the text padding of top and bottom. defaut:5.
|ignoreDataShow|false||Whether to show ignored data on tooltip.
diff --git a/Documentation~/zh/api.md b/Documentation~/zh/api.md
index fb67994e..be4654ab 100644
--- a/Documentation~/zh/api.md
+++ b/Documentation~/zh/api.md
@@ -1031,7 +1031,11 @@ slug: /api
|GetSerieLabelName()||public static string GetSerieLabelName(string prefix, int i, int j)|
|GetString()||public static string GetString(string prefix, int suffix)|
|IntToStr()||public static string IntToStr(int value, string numericFormatter = "")|
+|NumberToDateStr()||public static string NumberToDateStr(double timestamp, string formatter)|
+|NumberToDateTime()||public static DateTime NumberToDateTime(double timestamp)|
|NumberToStr()||public static string NumberToStr(double value, string formatter)|
+|NumberToTimeSpan()||public static TimeSpan NumberToTimeSpan(double timestamp)|
+|NumberToTimeStr()||public static string NumberToTimeStr(double timestamp, string formatter)|
## ChartConst
@@ -1361,12 +1365,13 @@ DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息
|API|版本|描述|
|--|--|--|
-|GetDateTime()||public static DateTime GetDateTime(double timestamp)|
-|GetDateTime()||public static DateTime GetDateTime(int timestamp)|
+|GetDateTime()||public static DateTime GetDateTime(double timestamp, bool local = true)|
|GetDefaultDateTimeString()||public static string GetDefaultDateTimeString(int timestamp, double range = 0)|
|GetTimestamp()||public static int GetTimestamp()|
-|GetTimestamp()||public static int GetTimestamp(DateTime time)|
-|GetTimestamp()||public static int GetTimestamp(string dateTime)|
+|GetTimestamp()||public static int GetTimestamp(DateTime time, bool local = false)|
+|GetTimestamp()||public static int GetTimestamp(string dateTime, bool local = false)|
+|IsDateOrTimeRegex()||public static bool IsDateOrTimeRegex(string regex)|
+|IsDateOrTimeRegex()||public static bool IsDateOrTimeRegex(string regex, ref bool date, ref string formatter)|
## DebugInfo
diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md
index b0e7be0b..46bfe4e4 100644
--- a/Documentation~/zh/changelog.md
+++ b/Documentation~/zh/changelog.md
@@ -76,6 +76,7 @@ slug: /changelog
## master
+* (2024.09.09) 增加`numericFormatter`对`date`和`time`的支持
* (2024.09.03) 完善`AreaStyle`的`origin`参数设置区域填充起始位置
* (2024.09.01) 增加`Ring`的`radiusGradient`参数设置渐变方向
* (2024.09.01) 优化`Axis`为时间轴时首个Label的位置
diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md
index 396a2ef9..703bf268 100644
--- a/Documentation~/zh/configuration.md
+++ b/Documentation~/zh/configuration.md
@@ -1223,7 +1223,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart
|opacity|1||透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。
|itemMarker|||提示框单项的字符标志。用在Tooltip中。
|itemFormatter|||提示框单项的字符串模版格式器。具体配置参考`Tooltip`的`formatter`
-|numericFormatter|||标准数字格式字符串。用于将数值格式化显示为字符串。 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
+|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
注意:date和time格式需要`v3.12.0`以上版本才支持。
|cornerRadius|||圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。
```mdx-code-block
@@ -1282,7 +1282,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart
|autoRotate|false|v3.6.0|是否自动旋转。
|distance|||距离轴线的距离。
|formatter|||标签内容字符串模版格式器。支持用 \n 换行。部分组件的格式器会不生效。
模板通配符有以下这些,部分只适用于固定的组件:
`{.}`:圆点标记。
`{a}`:系列名。
`{b}`:X轴类目名或数据名。
`{c}`:数据值。
`{d}`:百分比。
`{e}`:数据名。
`{f}`:数据和。
`{g}`:数据总个数。
`{h}`:十六进制颜色值。
`{y}`:Y轴的类目名。
`{value}`:坐标轴或图例的值。
以下通配符适用UITable组件:
`{name}`: 表格的行名。
`{index}`:表格的行号。
以下通配符适用UIStatistc组件:
`{title}`:标题文本。
`{dd}`:天。
`{hh}`:小时。
`{mm}`:分钟。
`{ss}`:秒。
`{fff}`:毫秒。
`{d}`:天。
`{h}`:小时。
`{m}`:分钟。
`{s}`:秒。
`{f}`:毫秒。
示例:“{b}:{c}”
-|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss
数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
注意:date和time格式需要`v3.12.0`以上版本才支持。
|width|0||标签的宽度。一般不用指定,不指定时则自动是文字的宽度。
|height|0||标签的高度。一般不用指定,不指定时则自动是文字的高度。
|icon|||图标样式。 [IconStyle](#iconstyle)|
@@ -1757,6 +1757,18 @@ Radar coordinate conponnet for radar charts. 雷达图坐标系组件,只适
> class in XCharts.Runtime / 继承自: [Serie](#serie)
+```mdx-code-block
+
+```
+
+|参数|默认|版本|描述|
+|--|--|--|--|
+|radiusGradient|false|v3.12.0|是否开启半径方向的渐变效果。
+
+```mdx-code-block
+
+```
+
## Scatter
> class in XCharts.Runtime / 继承自: [BaseScatter](#basescatter)
@@ -2278,7 +2290,7 @@ Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种
|fixedHeight|0||固定高度。比 minHeight 优先。
|minWidth|0||最小宽度。如若 fixedWidth 设有值,优先取 fixedWidth。
|minHeight|0||最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
-|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss
数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
注意:date和time格式需要`v3.12.0`以上版本才支持。
|paddingLeftRight|10||左右边距。
|paddingTopBottom|10||上下边距。
|ignoreDataShow|false||是否显示忽略数据在tooltip上。
diff --git a/Runtime/Component/Child/ItemStyle.cs b/Runtime/Component/Child/ItemStyle.cs
index 69384b9b..8fe51003 100644
--- a/Runtime/Component/Child/ItemStyle.cs
+++ b/Runtime/Component/Child/ItemStyle.cs
@@ -209,10 +209,29 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_ItemMarker, value)) SetVerticesDirty(); }
}
///
- /// Standard numeric format strings.
- /// ||标准数字格式字符串。用于将数值格式化显示为字符串。
- /// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
- /// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
+ /// Standard number and date format string. Used to format a Double value or a DateTime date as a string.
+ /// numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
+ /// The number format uses the Axx format: A is a single-character format specifier that supports C currency,
+ /// D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal.
+ /// xx is precision specification, from 0-99. E.g. F1, E2
+ /// Date format: Starts with `date`, which is used to format DateTime. Common date formats are:
+ /// yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
+ /// Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are:
+ /// d day, HH hour, mm minute, ss second, fffffff fractional part.
+ /// Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped.
+ /// For example: time:HH\:mm\:ss
+ /// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+ /// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+ /// Note: The date and time formats are only supported by 'v3.12.0' or later.
+ /// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
+ /// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
+ /// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
+ /// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
+ /// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
+ /// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
+ /// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+ /// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
+ /// 注意:date和time格式需要`v3.12.0`以上版本才支持。
///
public string numericFormatter
{
diff --git a/Runtime/Component/Label/LabelStyle.cs b/Runtime/Component/Label/LabelStyle.cs
index 1b6a9555..743a8a7a 100644
--- a/Runtime/Component/Label/LabelStyle.cs
+++ b/Runtime/Component/Label/LabelStyle.cs
@@ -184,16 +184,29 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
}
///
- /// Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
- /// The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
- /// Date format Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: yyyy-MM-dd HH:mm:ss
+ /// Standard number and date format string. Used to format a Double value or a DateTime date as a string.
+ /// numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
+ /// The number format uses the Axx format: A is a single-character format specifier that supports C currency,
+ /// D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal.
+ /// xx is precision specification, from 0-99. E.g. F1, E2
+ /// Date format: Starts with `date`, which is used to format DateTime. Common date formats are:
+ /// yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
+ /// Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are:
+ /// d day, HH hour, mm minute, ss second, fffffff fractional part.
+ /// Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped.
+ /// For example: time:HH\:mm\:ss
/// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
/// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+ /// Note: The date and time formats are only supported by 'v3.12.0' or later.
/// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
/// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
- /// 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss
+ /// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
+ /// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
+ /// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
/// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
- /// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+ /// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+ /// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
+ /// 注意:date和time格式需要`v3.12.0`以上版本才支持。
///
public string numericFormatter
{
@@ -405,7 +418,7 @@ namespace XCharts.Runtime
public virtual string GetFormatterContent(int labelIndex, double value, double minValue, double maxValue, bool isLog = false)
{
var newNumericFormatter = numericFormatter;
- if (value == 0)
+ if (value == 0 && !DateTimeUtil.IsDateOrTimeRegex(newNumericFormatter))
{
newNumericFormatter = "f0";
}
@@ -444,6 +457,8 @@ namespace XCharts.Runtime
}
}
+ private static bool isDateFormatter = false;
+ private static string newFormatter = null;
public string GetFormatterDateTime(int labelIndex, double value, double minValue, double maxValue)
{
var timestamp = (int)value;
@@ -457,7 +472,17 @@ namespace XCharts.Runtime
{
try
{
- dateString = dateTime.ToString(numericFormatter);
+ if(DateTimeUtil.IsDateOrTimeRegex(numericFormatter, ref isDateFormatter, ref newFormatter))
+ {
+ if(isDateFormatter)
+ dateString = ChartCached.NumberToDateStr(timestamp, newFormatter);
+ else
+ dateString = ChartCached.NumberToTimeStr(timestamp, newFormatter);
+ }
+ else
+ {
+ dateString = dateTime.ToString(numericFormatter);
+ }
}
catch
{
diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs
index 7711fd9e..68e797a9 100644
--- a/Runtime/Component/Tooltip/Tooltip.cs
+++ b/Runtime/Component/Tooltip/Tooltip.cs
@@ -293,16 +293,29 @@ namespace XCharts.Runtime
///
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
///
- /// Standard number and date format string. Used to format a Double value or a DateTime date as a string. numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
- /// The number format uses the Axx format: A is a single-character format specifier that supports C currency, D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal. xx is precision specification, from 0-99. E.g. F1, E2
- /// Date format Common date formats are: yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: yyyy-MM-dd HH:mm:ss
+ /// Standard number and date format string. Used to format a Double value or a DateTime date as a string.
+ /// numericFormatter is used as an argument to either `Double.ToString ()` or `DateTime.ToString()`.
+ /// The number format uses the Axx format: A is a single-character format specifier that supports C currency,
+ /// D decimal, E exponent, F fixed-point number, G regular, N digit, P percentage, R round trip, and X hexadecimal.
+ /// xx is precision specification, from 0-99. E.g. F1, E2
+ /// Date format: Starts with `date`, which is used to format DateTime. Common date formats are:
+ /// yyyy year, MM month, dd day, HH hour, mm minute, ss second, fff millisecond. For example: date:yyyy-MM-dd HH:mm:ss
+ /// Time format: Starts with `time`, which is used to format TimeSpan. Common time formats are:
+ /// d day, HH hour, mm minute, ss second, fffffff fractional part.
+ /// Only the version of Unity2018 or later can support formatting, and the characters inside should be escaped.
+ /// For example: time:HH\:mm\:ss
/// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
/// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
+ /// Note: The date and time formats are only supported by 'v3.12.0' or later.
/// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。
/// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2
- /// 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss
+ /// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss
+ /// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
+ /// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss
/// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
- /// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+ /// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
+ /// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings
+ /// 注意:date和time格式需要`v3.12.0`以上版本才支持。
///
public string numericFormatter
{
diff --git a/Runtime/Internal/Utilities/ChartCached.cs b/Runtime/Internal/Utilities/ChartCached.cs
index 1a07f332..98547d46 100644
--- a/Runtime/Internal/Utilities/ChartCached.cs
+++ b/Runtime/Internal/Utilities/ChartCached.cs
@@ -23,6 +23,8 @@ namespace XCharts.Runtime
private static Dictionary> s_NumberToStr = new Dictionary>();
private static Dictionary> s_PrecisionToStr = new Dictionary>();
private static Dictionary> s_StringIntDict = new Dictionary>();
+ private static Dictionary s_TimestampToDateTimeDict = new Dictionary();
+ private static Dictionary s_NumberToTimeSpanDict = new Dictionary();
private static CultureInfo GetDefaultCultureInfo()
{
@@ -64,10 +66,19 @@ namespace XCharts.Runtime
}
if (!s_NumberToStr[value].ContainsKey(formatter))
{
+ bool isDateFormatter = false;
+ string newFormatter = null;
if (string.IsNullOrEmpty(formatter))
{
s_NumberToStr[value][formatter] = value.ToString();
}
+ else if (DateTimeUtil.IsDateOrTimeRegex(formatter,ref isDateFormatter, ref newFormatter))
+ {
+ if(isDateFormatter)
+ s_NumberToStr[value][formatter] = NumberToDateStr(value, newFormatter);
+ else
+ s_NumberToStr[value][formatter] = NumberToTimeStr(value, newFormatter);
+ }
else if (formatter.StartsWith(NUMERIC_FORMATTER_D) ||
formatter.StartsWith(NUMERIC_FORMATTER_d) ||
formatter.StartsWith(NUMERIC_FORMATTER_X) ||
@@ -89,6 +100,56 @@ namespace XCharts.Runtime
return NumberToStr(value, numericFormatter);
}
+ public static string NumberToDateStr(double timestamp, string formatter)
+ {
+ var dt = NumberToDateTime(timestamp);
+ try
+ {
+ return dt.ToString(formatter, ci);
+ }
+ catch (Exception)
+ {
+ XLog.LogError("Not support DateTime format: " + formatter);
+ return timestamp.ToString();
+ }
+ }
+
+ public static string NumberToTimeStr(double timestamp, string formatter)
+ {
+ try
+ {
+ var ts = NumberToTimeSpan(timestamp);
+#if UNITY_2018_3_OR_NEWER
+ return ts.ToString(formatter, ci);
+#else
+ return ts.ToString();
+#endif
+ }
+ catch (Exception)
+ {
+ XLog.LogError("Not support TimeSpan format: " + formatter);
+ return timestamp.ToString();
+ }
+ }
+
+ public static DateTime NumberToDateTime(double timestamp)
+ {
+ if (!s_TimestampToDateTimeDict.ContainsKey(timestamp))
+ {
+ s_TimestampToDateTimeDict[timestamp] = DateTimeUtil.GetDateTime(timestamp);
+ }
+ return s_TimestampToDateTimeDict[timestamp];
+ }
+
+ public static TimeSpan NumberToTimeSpan(double timestamp)
+ {
+ if(!s_NumberToTimeSpanDict.ContainsKey(timestamp))
+ {
+ s_NumberToTimeSpanDict[timestamp] = TimeSpan.FromSeconds(timestamp);
+ }
+ return s_NumberToTimeSpanDict[timestamp];
+ }
+
public static string ColorToStr(Color color)
{
if (s_ColorToStr.ContainsKey(color))
diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs
index 00eaa3da..6459f546 100644
--- a/Runtime/Utilities/DateTimeUtil.cs
+++ b/Runtime/Utilities/DateTimeUtil.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using UnityEngine;
namespace XCharts.Runtime
@@ -7,10 +8,11 @@ namespace XCharts.Runtime
public static class DateTimeUtil
{
#if UNITY_2018_3_OR_NEWER
- private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
+ private static readonly DateTime k_LocalDateTime1970 = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
#else
- private static readonly DateTime k_DateTime1970 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
+ private static readonly DateTime k_LocalDateTime1970 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
#endif
+ private static readonly DateTime k_DateTime1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static readonly int ONE_SECOND = 1;
public static readonly int ONE_MINUTE = ONE_SECOND * 60;
public static readonly int ONE_HOUR = ONE_MINUTE * 60;
@@ -26,22 +28,54 @@ namespace XCharts.Runtime
//private static string s_MinuteDateFormatter = "mm:ss";
private static string s_SecondDateFormatter = "HH:mm:ss";
//private static string s_FullDateFormatter = "yyyy-MM-dd HH:mm:ss";
+ private static Regex s_DateOrTimeRegex = new Regex(@"^(date|time)\s*[:\s]+(.*)", RegexOptions.IgnoreCase);
+
+ public static bool IsDateOrTimeRegex(string regex)
+ {
+ return regex.StartsWith("date") || regex.StartsWith("time");
+ }
+
+ public static bool IsDateOrTimeRegex(string regex, ref bool date, ref string formatter)
+ {
+ if(IsDateOrTimeRegex(regex))
+ {
+ if(regex == "date" || regex == "time")
+ {
+ date = regex == "date";
+ formatter = "";
+ return true;
+ }
+ var mc = s_DateOrTimeRegex.Matches(regex);
+ date = mc[0].Groups[1].Value == "date";
+ formatter = mc[0].Groups[2].Value;
+ return true;
+ }
+ return false;
+ }
public static int GetTimestamp()
{
- return (int)(DateTime.Now - k_DateTime1970).TotalSeconds;
+ return (int)(DateTime.Now - k_LocalDateTime1970).TotalSeconds;
}
- public static int GetTimestamp(DateTime time)
+ public static int GetTimestamp(DateTime time, bool local = false)
{
- return (int)(time - k_DateTime1970).TotalSeconds;
+ if (local)
+ {
+ return (int)(time - k_LocalDateTime1970).TotalSeconds;
+ }
+ else
+ {
+ return (int)(time - k_DateTime1970).TotalSeconds;
+ }
}
- public static int GetTimestamp(string dateTime)
+ public static int GetTimestamp(string dateTime, bool local = false)
{
try
{
- return GetTimestamp(DateTime.Parse(dateTime));
+
+ return GetTimestamp(DateTime.Parse(dateTime), local);
}
catch (Exception e)
{
@@ -49,14 +83,9 @@ namespace XCharts.Runtime
}
}
- public static DateTime GetDateTime(double timestamp)
+ public static DateTime GetDateTime(double timestamp, bool local = true)
{
- return k_DateTime1970.AddSeconds(timestamp);
- }
-
- public static DateTime GetDateTime(int timestamp)
- {
- return k_DateTime1970.AddSeconds(timestamp);
+ return local ? k_LocalDateTime1970.AddSeconds(timestamp) : k_DateTime1970.AddSeconds(timestamp);
}
public static string GetDefaultDateTimeString(int timestamp, double range = 0)