mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
增加numericFormatter对date和time的支持
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()`. <br /> 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<br /> 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<br /> 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<br /> number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
|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. <br /> Template placeholder have the following, some of which apply only to fixed components: <br /> `{.}` : indicates the dot mark. <br /> `{a}` : indicates the series name. <br /> `{b}` : category value of x axis or data name. <br /> `{c}` : data value. <br /> `{d}` : percentage. <br /> `{e}` : indicates the data name. <br /> `{f}` : data sum. <br /> `{g}` : indicates the total number of data. <br /> `{h}` : hexadecimal color value. <br /> `{y}` : category value of y axis. <br /> `{value}` : The value of the axis or legend. <br /> The following placeholder apply to `UITable` components: <br /> `{name}` : indicates the row name of the table. <br /> `{index}` : indicates the row number of the table. <br /> The following placeholder apply to `UIStatistc` components: <br /> `{title}` : title text. <br /> `{dd}` : day. <br /> `{hh}` : hours. <br /> `{mm}` : minutes. <br /> `{ss}` : second. <br /> `{fff}` : milliseconds. <br /> `{d}` : day. <br /> `{h}` : hours. <br /> `{m}` : minutes. <br /> `{s}` : second. <br /> `{f}` : milliseconds. <br /> Example :{b}:{c}<br />
|
||||
|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()`. <br /> 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<br /> 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<br /> number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
|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()`. <br /> 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<br /> 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<br /> 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<br /> number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
|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
|
||||
<APITable name="Ring">
|
||||
```
|
||||
|
||||
|
||||
|field|default|since|comment|
|
||||
|--|--|--|--|
|
||||
|radiusGradient|false|v3.12.0|Whether to use gradient color in pie chart.
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
## 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()`. <br /> 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<br /> 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<br /> number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
|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()`. <br /> 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<br /> 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<br /> 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<br /> number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/> Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
|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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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的位置
|
||||
|
||||
@@ -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()的参数。<br/> 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/> 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/> 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/> 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/> 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings <br/> 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/> 注意: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 换行。部分组件的格式器会不生效。<br/> 模板通配符有以下这些,部分只适用于固定的组件:<br/> `{.}`:圆点标记。<br/> `{a}`:系列名。<br/> `{b}`:X轴类目名或数据名。<br/> `{c}`:数据值。<br/> `{d}`:百分比。<br/> `{e}`:数据名。<br/> `{f}`:数据和。<br/> `{g}`:数据总个数。<br/> `{h}`:十六进制颜色值。<br/> `{y}`:Y轴的类目名。<br/> `{value}`:坐标轴或图例的值。<br/> 以下通配符适用UITable组件:<br/> `{name}`: 表格的行名。<br/> `{index}`:表格的行号。<br/> 以下通配符适用UIStatistc组件:<br/> `{title}`:标题文本。<br/> `{dd}`:天。<br/> `{hh}`:小时。<br/> `{mm}`:分钟。<br/> `{ss}`:秒。<br/> `{fff}`:毫秒。<br/> `{d}`:天。<br/> `{h}`:小时。<br/> `{m}`:分钟。<br/> `{s}`:秒。<br/> `{f}`:毫秒。<br/> 示例:“{b}:{c}”
|
||||
|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/> 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/> 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss<br/> 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/> 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
|
||||
|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/> 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/> 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/> 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/> 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/> 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings <br/> 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/> 注意: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
|
||||
<APITable name="Ring">
|
||||
```
|
||||
|
||||
|参数|默认|版本|描述|
|
||||
|--|--|--|--|
|
||||
|radiusGradient|false|v3.12.0|是否开启半径方向的渐变效果。
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
## 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()的参数。<br/> 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/> 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss<br/> 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/> 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings
|
||||
|numericFormatter|||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/> 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/> 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/> 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/> 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/> 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings <br/> 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/> 注意:date和time格式需要`v3.12.0`以上版本才支持。
|
||||
|paddingLeftRight|10||左右边距。
|
||||
|paddingTopBottom|10||上下边距。
|
||||
|ignoreDataShow|false||是否显示忽略数据在tooltip上。
|
||||
|
||||
@@ -209,10 +209,29 @@ namespace XCharts.Runtime
|
||||
set { if (PropertyUtil.SetClass(ref m_ItemMarker, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 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()`. <br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
/// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/>
|
||||
/// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/>
|
||||
/// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/>
|
||||
/// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
|
||||
/// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/>
|
||||
/// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/>
|
||||
/// 日期格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-date-and-time-format-strings <br/>
|
||||
/// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/>
|
||||
/// 注意:date和time格式需要`v3.12.0`以上版本才支持。
|
||||
/// </summary>
|
||||
public string numericFormatter
|
||||
{
|
||||
|
||||
@@ -184,16 +184,29 @@ namespace XCharts.Runtime
|
||||
set { if (PropertyUtil.SetClass(ref m_Formatter, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 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()`. <br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// 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()`. <br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
/// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/>
|
||||
/// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/>
|
||||
/// 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss<br/>
|
||||
/// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/>
|
||||
/// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
|
||||
/// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/>
|
||||
/// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/>
|
||||
/// 日期格式化参考: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 <br/>
|
||||
/// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/>
|
||||
/// 注意:date和time格式需要`v3.12.0`以上版本才支持。
|
||||
/// </summary>
|
||||
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
|
||||
{
|
||||
|
||||
@@ -293,16 +293,29 @@ namespace XCharts.Runtime
|
||||
/// </summary>
|
||||
public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
|
||||
/// <summary>
|
||||
/// 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()`. <br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// 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()`. <br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// 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<br />
|
||||
/// number format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// date format reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings<br/>
|
||||
/// Note: The date and time formats are only supported by 'v3.12.0' or later.<br/>
|
||||
/// ||标准数字和日期格式字符串。用于将Double数值或DateTime日期格式化显示为字符串。numericFormatter用来作为Double.ToString()或DateTime.ToString()的参数。<br/>
|
||||
/// 数字格式使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。如:F1, E2<br/>
|
||||
/// 日期格式常见的格式:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:yyyy-MM-dd HH:mm:ss<br/>
|
||||
/// 日期格式:以`date`开头,用来格式化DateTime,常见格式有:yyyy年,MM月,dd日,HH时,mm分,ss秒,fff毫秒。如:date:yyyy-MM-dd HH:mm:ss<br/>
|
||||
/// 时间格式:以`time`开头,用来格式化TimeSpan,常见格式有:d日,HH时,mm分,ss秒,fffffff小数部分。
|
||||
/// 需要Unity2018以上版本才支持格式化,并且里面的字符要转义。如:time:d\.HH\:mm\:ss<br/>
|
||||
/// 数值格式化参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings <br/>
|
||||
/// 日期格式化参考: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 <br/>
|
||||
/// 时间格式化参考:https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/standard-timespan-format-strings <br/>
|
||||
/// 注意:date和time格式需要`v3.12.0`以上版本才支持。
|
||||
/// </summary>
|
||||
public string numericFormatter
|
||||
{
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace XCharts.Runtime
|
||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||
private static Dictionary<string, Dictionary<int, string>> s_StringIntDict = new Dictionary<string, Dictionary<int, string>>();
|
||||
private static Dictionary<double, DateTime> s_TimestampToDateTimeDict = new Dictionary<double, DateTime>();
|
||||
private static Dictionary<double, TimeSpan> s_NumberToTimeSpanDict = new Dictionary<double, TimeSpan>();
|
||||
|
||||
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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user