From 61a2da10ba3a8cb55cf5abbb5b870cdaeb4b6935 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 23 Jan 2024 22:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`{y}`=E9=80=9A=E9=85=8D?= =?UTF-8?q?=E7=AC=A6=E7=94=A8=E4=BA=8E=E8=8E=B7=E5=8F=96Y=E8=BD=B4?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E7=9B=AE=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/en/configuration.md | 6 +-- Documentation~/zh/changelog.md | 2 + Documentation~/zh/configuration.md | 6 +-- Runtime/Component/Label/LabelStyle.cs | 6 ++- Runtime/Component/Label/SerieLabelHelper.cs | 6 +-- Runtime/Component/Tooltip/Tooltip.cs | 6 ++- Runtime/Component/Tooltip/TooltipHelper.cs | 3 +- Runtime/Helper/FormatterHelper.cs | 56 +++++++++++++++++++-- Runtime/Serie/SerieHandler.cs | 4 +- 9 files changed, 74 insertions(+), 21 deletions(-) diff --git a/Documentation~/en/configuration.md b/Documentation~/en/configuration.md index 5c9dba5d..ecdbbd29 100644 --- a/Documentation~/en/configuration.md +++ b/Documentation~/en/configuration.md @@ -1280,7 +1280,7 @@ Text label of chart, to explain some data information about graphic item like va |rotate|||Rotation of label. |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 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.
`{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}
+|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
|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. @@ -2303,8 +2303,8 @@ Tooltip component. |type|||Indicator type.
`Tooltip.Type`:
- `Line`: line indicator.
- `Shadow`: shadow crosshair indicator.
- `None`: no indicator displayed.
- `Corss`: crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
- `Auto`: Auto select indicator according to serie type.
| |trigger|||Type of triggering.
`Tooltip.Trigger`:
- `Item`: Triggered by data item, which is mainly used for charts that don't have a category axis like scatter charts or pie charts.
- `Axis`: Triggered by axes, which is mainly used for charts that have category axes, like bar charts or line charts.
- `None`: Trigger nothing.
- `Auto`: Auto select trigger according to serie type.
| |position||v3.3.0|Type of position.
`Tooltip.Position`:
- `Auto`: Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position.
- `Custom`: Custom. Fully customize display position (x,y).
- `FixedX`: Just fix the coordinate X. Y follows the mouse position.
- `FixedY`:
| -|itemFormatter|||a string template formatter for a single Serie or data item content. Support for wrapping lines with \n. Template variables are {.}, {a}, {b}, {c}, {d}.
{.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.
{a} is the series name of the serie that is currently indicated or whose index is 0.
{b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
{c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
{d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
{e} is the name of the data item serieData that is currently indicated or whose index is 0.
{f} is sum of data.
{.1} represents a dot from serie corresponding color that specifies index as 1.
1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
{c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
{c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).
{d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).
{d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).
Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"
-|titleFormatter|||String template formatter for tooltip title content. \n line wrapping is supported. The placeholder {i} can be set separately to indicate that title is ignored and not displayed. Template variables are {.}, {a}, {b}, {c}, {d}, {e}, {f}, and {g}.
{.} is the dot of the corresponding color of serie currently indicated or index 0.
{a} is the series name name of serie currently indicated or index 0.
{b} is the name of the serie data item serieData currently indicated or index 0, or the category value (such as the X-axis of a line chart).
{c} is the value of the serie y-dimension (dimesion is 1) currently indicated or index is 0.
{d} is the serie y-dimensional (dimesion 1) percentage value of the currently indicated or index 0, note without the % sign.
{e} is the name of the serie data item serieData currently indicated or whose index is 0.
{h} is the hexadecimal color value of serieData for the serie data item currently indicated or index 0.
{f} is the sum of data.
{g} indicates the total number of data.
{.1} represents a dot of the corresponding color with serie specified as index 1.
The 1 in {a1}, {b1}, {c1} represents serie where index is specified as 1.
{c1:2} represents the third data of the current indicator data item in serie with index 1 (one data item has multiple data, index 2 represents the third data).
{c1:2-2} represents the third data of serie third data item with index 1 (that is, the number of data items must be specified when specifying the number of data items).
{d1:2:f2} indicates that a format string with a single value is f2 (numericFormatter is used if no value is specified).
{d:0.##} indicates that the format string with a value specified alone is 0.## # (for percentages, preserving a 2-digit significant number while avoiding the "100.00%" situation with f2).
example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1}, {c1:1-1: f1}" +|itemFormatter|||a string template formatter for a single Serie or data item content. Support for wrapping lines with \n. Template variables are {.}, {a}, {b}, {c}, {d}.
{.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.
{a} is the series name of the serie that is currently indicated or whose index is 0.
{b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
{c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
{d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
{e} is the name of the data item serieData that is currently indicated or whose index is 0.
{f} is sum of data.
{y} is category value of y axis.
{.1} represents a dot from serie corresponding color that specifies index as 1.
1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
{c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
{c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).
{d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).
{d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).
Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"
+|titleFormatter|||String template formatter for tooltip title content. \n line wrapping is supported. The placeholder {i} can be set separately to indicate that title is ignored and not displayed. Template variables are {.}, {a}, {b}, {c}, {d}, {e}, {f}, and {g}.
{.} is the dot of the corresponding color of serie currently indicated or index 0.
{a} is the series name name of serie currently indicated or index 0.
{b} is the name of the serie data item serieData currently indicated or index 0, or the category value (such as the X-axis of a line chart).
{c} is the value of the serie y-dimension (dimesion is 1) currently indicated or index is 0.
{d} is the serie y-dimensional (dimesion 1) percentage value of the currently indicated or index 0, note without the % sign.
{e} is the name of the serie data item serieData currently indicated or whose index is 0.
{h} is the hexadecimal color value of serieData for the serie data item currently indicated or index 0.
{f} is the sum of data.
{g} indicates the total number of data.
{y} is category value of y axis.
{.1} represents a dot of the corresponding color with serie specified as index 1.
The 1 in {a1}, {b1}, {c1} represents serie where index is specified as 1.
{c1:2} represents the third data of the current indicator data item in serie with index 1 (one data item has multiple data, index 2 represents the third data).
{c1:2-2} represents the third data of serie third data item with index 1 (that is, the number of data items must be specified when specifying the number of data items).
{d1:2:f2} indicates that a format string with a single value is f2 (numericFormatter is used if no value is specified).
{d:0.##} indicates that the format string with a value specified alone is 0.## # (for percentages, preserving a 2-digit significant number while avoiding the "100.00%" situation with f2).
example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1}, {c1:1-1: f1}" |marker|||the marker of serie. |fixedWidth|0||Fixed width. Higher priority than minWidth. |fixedHeight|0||Fixed height. Higher priority than minHeight. diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index f629f353..3ee402e6 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -70,6 +70,8 @@ slug: /changelog ## master +* (2024.01.23) 增加`{y}`通配符用于获取Y轴的类目名 +* (2024.01.23) 增加`Line`支持X轴和Y轴都为`Category`类目轴 * (2024.01.18) 修复`Animation`的`type`代码动态修改无效的问题 * (2024.01.13) 增加`Chart`的更多快捷创建图表菜单 * (2024.01.09) 增加`Background`的`borderStyle`,给图表默认设置圆角 diff --git a/Documentation~/zh/configuration.md b/Documentation~/zh/configuration.md index eece56c1..885954ea 100644 --- a/Documentation~/zh/configuration.md +++ b/Documentation~/zh/configuration.md @@ -1243,7 +1243,7 @@ Drawing grid in rectangular coordinate. Line chart, bar chart, and scatter chart |rotate|||文本的旋转。 |autoRotate|false|v3.6.0|是否自动旋转。 |distance|||距离轴线的距离。 -|formatter|||标签内容字符串模版格式器。支持用 \n 换行。部分组件的格式器会不生效。
模板通配符有以下这些,部分只适用于固定的组件:
`{.}`:圆点标记。
`{a}`:系列名。
`{b}`:类目值或数据名。
`{c}`:数据值。
`{d}`:百分比。
`{e}`:数据名。
`{f}`:数据和。
`{g}`:数据总个数。
`{h}`:十六进制颜色值。
`{value}`:坐标轴或图例的值。
以下通配符适用UITable组件:
`{name}`: 表格的行名。
`{index}`:表格的行号。
以下通配符适用UIStatistc组件:
`{title}`:标题文本。
`{dd}`:天。
`{hh}`:小时。
`{mm}`:分钟。
`{ss}`:秒。
`{fff}`:毫秒。
`{d}`:天。
`{h}`:小时。
`{m}`:分钟。
`{s}`:秒。
`{f}`:毫秒。
示例:“{b}:{c}” +|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 |width|0||标签的宽度。一般不用指定,不指定时则自动是文字的宽度。 |height|0||标签的高度。一般不用指定,不指定时则自动是文字的高度。 @@ -2232,8 +2232,8 @@ Serie的状态样式。Serie的状态有正常,高亮,淡出,选中四种 |type|||提示框指示器类型。
`Tooltip.Type`:
- `Line`: 直线指示器
- `Shadow`: 阴影指示器
- `None`: 无指示器
- `Corss`: 十字准星指示器。坐标轴显示Label和交叉线。
- `Auto`: 根据serie的类型自动选择显示指示器。
| |trigger|||触发类型。
`Tooltip.Trigger`:
- `Item`: 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
- `Axis`: 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
- `None`: 什么都不触发。
- `Auto`: 根据serie的类型自动选择触发类型。
| |position||v3.3.0|显示位置类型。
`Tooltip.Position`:
- `Auto`: 自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。
- `Custom`: 自定义。完全自定义显示位置(x,y)。
- `FixedX`: 只固定坐标X。Y跟随鼠标位置。
- `FixedY`:
| -|itemFormatter|||提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用|来表示多个列的分隔。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
{i}或-表示忽略当前项。 {.}为当前所指示的serie或数据项的对应颜色的圆点。
{a}为当前所指示的serie或数据项的系列名name。
{b}为当前所指示的serie或数据项的数据项serieData的name,或者类目值(如折线图的X轴)。
{c}为当前所指示的serie或数据项的y维(dimesion为1)的数值。
{d}为当前所指示的serie或数据项的y维(dimesion为1)百分比值,注意不带%号。
{e}为当前所指示的serie或数据项的数据项serieData的name。
{f}为当前所指示的serie的默认维度的数据总和。
{g}为当前所指示的serie的数据总个数。
{h}为当前所指示的serie的十六进制颜色值。
{c0}表示当前数据项维度为0的数据。
{c1}表示当前数据项维度为1的数据。
{d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。
|表示多个列的分隔。
示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}" -|titleFormatter|||提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
{.}为当前所指示或index为0的serie的对应颜色的圆点。
{a}为当前所指示或index为0的serie的系列名name。
{b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。
{c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
{d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
{e}为当前所指示或index为0的serie的数据项serieData的name。
{h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。
{f}为数据总和。
{g}为数据总个数。
{.1}表示指定index为1的serie对应颜色的圆点。
{a1}、{b1}、{c1}中的1表示指定index为1的serie。
{c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
{c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。
{d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。
{d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。
示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}" +|itemFormatter|||提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用|来表示多个列的分隔。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
{i}或-表示忽略当前项。 {.}为当前所指示的serie或数据项的对应颜色的圆点。
{a}为当前所指示的serie或数据项的系列名name。
{b}为当前所指示的serie或数据项的数据项serieData的name,或者类目值(如折线图的X轴)。
{c}为当前所指示的serie或数据项的y维(dimesion为1)的数值。
{d}为当前所指示的serie或数据项的y维(dimesion为1)百分比值,注意不带%号。
{e}为当前所指示的serie或数据项的数据项serieData的name。
{f}为当前所指示的serie的默认维度的数据总和。
{g}为当前所指示的serie的数据总个数。
{h}为当前所指示的serie的十六进制颜色值。
{y}为当前所指示的serie的y轴的类目值。
{c0}表示当前数据项维度为0的数据。
{c1}表示当前数据项维度为1的数据。
{d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。
|表示多个列的分隔。
示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}", "{.}|{b}|{y}" +|titleFormatter|||提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。
{.}为当前所指示或index为0的serie的对应颜色的圆点。
{a}为当前所指示或index为0的serie的系列名name。
{b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。
{c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。
{d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。
{e}为当前所指示或index为0的serie的数据项serieData的name。
{h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。
{f}为数据总和。
{g}为数据总个数。
{f}为value所对应的y轴的类目值。
{.1}表示指定index为1的serie对应颜色的圆点。
{a1}、{b1}、{c1}中的1表示指定index为1的serie。
{c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
{c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。
{d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。
{d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。
示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}" |marker|||serie的符号标志。 |fixedWidth|0||固定宽度。比 minWidth 优先。 |fixedHeight|0||固定高度。比 minHeight 优先。 diff --git a/Runtime/Component/Label/LabelStyle.cs b/Runtime/Component/Label/LabelStyle.cs index 5ae385c4..1b6a9555 100644 --- a/Runtime/Component/Label/LabelStyle.cs +++ b/Runtime/Component/Label/LabelStyle.cs @@ -123,13 +123,14 @@ namespace XCharts.Runtime /// 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 or data 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.
@@ -151,13 +152,14 @@ namespace XCharts.Runtime /// 模板通配符有以下这些,部分只适用于固定的组件:
/// `{.}`:圆点标记。
/// `{a}`:系列名。
- /// `{b}`:类目值或数据名。
+ /// `{b}`:X轴类目名或数据名。
/// `{c}`:数据值。
/// `{d}`:百分比。
/// `{e}`:数据名。
/// `{f}`:数据和。
/// `{g}`:数据总个数。
/// `{h}`:十六进制颜色值。
+ /// `{y}`:Y轴的类目名。
/// `{value}`:坐标轴或图例的值。
/// 以下通配符适用UITable组件:
/// `{name}`: 表格的行名。
diff --git a/Runtime/Component/Label/SerieLabelHelper.cs b/Runtime/Component/Label/SerieLabelHelper.cs index 48532686..2dc111e4 100644 --- a/Runtime/Component/Label/SerieLabelHelper.cs +++ b/Runtime/Component/Label/SerieLabelHelper.cs @@ -24,7 +24,7 @@ namespace XCharts.Runtime } public static string GetFormatterContent(Serie serie, SerieData serieData, - double dataValue, double dataTotal, LabelStyle serieLabel, Color color) + double dataValue, double dataTotal, LabelStyle serieLabel, Color color, BaseChart chart = null) { if (serieLabel == null) { @@ -45,7 +45,7 @@ namespace XCharts.Runtime { var content = serieLabel.formatter; FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, dataValue, - dataTotal, serieName, dataName, dataName, color, serieData); + dataTotal, serieName, dataName, dataName, color, serieData, chart); if (serieLabel.formatterFunction == null) return content; else @@ -70,7 +70,5 @@ namespace XCharts.Runtime serieData.labelObject.text.SetColor(label.textStyle.color); } } - - } } \ No newline at end of file diff --git a/Runtime/Component/Tooltip/Tooltip.cs b/Runtime/Component/Tooltip/Tooltip.cs index d737f210..13cac7f7 100644 --- a/Runtime/Component/Tooltip/Tooltip.cs +++ b/Runtime/Component/Tooltip/Tooltip.cs @@ -192,6 +192,7 @@ namespace XCharts.Runtime /// {h} is the hexadecimal color value of serieData for the serie data item currently indicated or index 0.
/// {f} is the sum of data.
/// {g} indicates the total number of data.
+ /// {y} is category value of y axis.
/// {.1} represents a dot of the corresponding color with serie specified as index 1.
/// The 1 in {a1}, {b1}, {c1} represents serie where index is specified as 1.
/// {c1:2} represents the third data of the current indicator data item in serie with index 1 (one data item has multiple data, index 2 represents the third data).
@@ -210,6 +211,7 @@ namespace XCharts.Runtime /// {h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。
/// {f}为数据总和。
/// {g}为数据总个数。
+ /// {f}为value所对应的y轴的类目值。
/// {.1}表示指定index为1的serie对应颜色的圆点。
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。
@@ -229,6 +231,7 @@ namespace XCharts.Runtime /// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
/// {e} is the name of the data item serieData that is currently indicated or whose index is 0.
/// {f} is sum of data.
+ /// {y} is category value of y axis.
/// {.1} represents a dot from serie corresponding color that specifies index as 1.
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
@@ -248,11 +251,12 @@ namespace XCharts.Runtime /// {f}为当前所指示的serie的默认维度的数据总和。
/// {g}为当前所指示的serie的数据总个数。
/// {h}为当前所指示的serie的十六进制颜色值。
+ /// {y}为当前所指示的serie的y轴的类目值。
/// {c0}表示当前数据项维度为0的数据。
/// {c1}表示当前数据项维度为1的数据。
/// {d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。
/// |表示多个列的分隔。
- /// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}" + /// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}", "{.}|{b}|{y}" /// public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } } /// diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index 50b5dbda..4c462262 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -43,7 +43,8 @@ namespace XCharts.Runtime param.category, param.serieData.name, param.color, - param.serieData); + param.serieData, + chart); foreach (var item in content.Split('|')) { param.columns.Add(item); diff --git a/Runtime/Helper/FormatterHelper.cs b/Runtime/Helper/FormatterHelper.cs index 02fcc327..43fbd35c 100644 --- a/Runtime/Helper/FormatterHelper.cs +++ b/Runtime/Helper/FormatterHelper.cs @@ -8,7 +8,7 @@ namespace XCharts.Runtime public static class FormatterHelper { public const string PH_NN = "\n"; - private static Regex s_Regex = new Regex(@"{([a-h|.]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase); + private static Regex s_Regex = new Regex(@"{([a-h|.|y]\d*)(:\d+(-\d+)?)?(:[c-g|x|p|r]\d*|:0\.#*)?}", RegexOptions.IgnoreCase); private static Regex s_RegexSub = new Regex(@"(0\.#*)|(\d+-\d+)|(\w+)|(\.)", RegexOptions.IgnoreCase); private static Regex s_RegexN = new Regex(@"^\d+", RegexOptions.IgnoreCase); private static Regex s_RegexN_N = new Regex(@"\d+-\d+", RegexOptions.IgnoreCase); @@ -16,8 +16,8 @@ namespace XCharts.Runtime private static Regex s_RegexNewLine = new Regex(@"[\\|/]+n|
|
|
", RegexOptions.IgnoreCase); private static Regex s_RegexForAxisLabel = new Regex(@"{value(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase); private static Regex s_RegexSubForAxisLabel = new Regex(@"(value)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase); - private static Regex s_RegexForSerieLabel = new Regex(@"{[a-h|\.]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase); - private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-h]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase); + private static Regex s_RegexForSerieLabel = new Regex(@"{[a-h|\.|y]\d*(:[c-g|x|p|r]\d*)?}", RegexOptions.IgnoreCase); + private static Regex s_RegexSubForSerieLabel = new Regex(@"(\.)|([a-h|y]\d*)|([c-g|x|p|r]\d*)", RegexOptions.IgnoreCase); public static bool NeedFormat(string content) { @@ -25,7 +25,7 @@ namespace XCharts.Runtime } /// - /// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}。 + /// 替换字符串中的通配符,支持的通配符有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}、{h}、{y}。 /// /// 要替换的字符串 /// 选中的数据项serieData索引 @@ -119,6 +119,33 @@ namespace XCharts.Runtime { content = content.Replace(old, ChartCached.NumberToStr(serie.dataCount, "")); } + else if (p == 'y' || p == 'Y') + { + if (chart != null) + { + var yAxis = chart.GetChartComponent(0); + if (yAxis != null) + { + var bIndex = dataIndex; + if (argsCount >= 2) + { + var args1Str = args[1].ToString(); + if (s_RegexN.IsMatch(args1Str)) bIndex = int.Parse(args1Str); + if (s_RegexFn.IsMatch(args1Str)) numericFormatter = args1Str; + } + if (yAxis.IsCategory()) + { + var yCategory = yAxis.GetData(bIndex); + content = content.Replace(old, yCategory); + } + else + { + var value = yAxis.context.pointerValue; + content = content.Replace(old, ChartCached.FloatToStr(value, numericFormatter)); + } + } + } + } else if (p == 'c' || p == 'C' || p == 'd' || p == 'D' || p == 'f' || p == 'f') { var isPercent = p == 'd' || p == 'D'; @@ -184,7 +211,7 @@ namespace XCharts.Runtime } public static void ReplaceSerieLabelContent(ref string content, string numericFormatter, int dataCount, double value, double total, - string serieName, string category, string dataName, Color color, SerieData serieData) + string serieName, string category, string dataName, Color color, SerieData serieData, BaseChart chart = null) { var mc = s_RegexForSerieLabel.Matches(content); foreach (var m in mc) @@ -253,6 +280,25 @@ namespace XCharts.Runtime { content = content.Replace(old, "#" + ChartCached.ColorToStr(color)); } + else if (p == 'y' || p == 'Y') + { + if (chart != null) + { + var yAxis = chart.GetChartComponent(0); + if (yAxis != null) + { + if (yAxis.IsCategory()) + { + var yCategory = yAxis.GetData(pIndex >= 0 ? pIndex : (int)value); + content = content.Replace(old, yCategory); + } + else + { + content = content.Replace(old, ChartCached.NumberToStr(value, numericFormatter)); + } + } + } + } } content = TrimAndReplaceLine(content); } diff --git a/Runtime/Serie/SerieHandler.cs b/Runtime/Serie/SerieHandler.cs index 59c42154..7ebfc2c7 100644 --- a/Runtime/Serie/SerieHandler.cs +++ b/Runtime/Serie/SerieHandler.cs @@ -503,7 +503,7 @@ namespace XCharts.Runtime var content = string.IsNullOrEmpty(currLabel.formatter) ? ChartCached.NumberToStr(value, currLabel.numericFormatter) : SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, - currLabel, color); + currLabel, color, chart); var offset = GetSerieDataLabelOffset(serieData, currLabel); labelObject.SetActive(currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value)); labelObject.SetText(content); @@ -525,7 +525,7 @@ namespace XCharts.Runtime var content = string.IsNullOrEmpty(currLabel.formatter) ? ChartCached.NumberToStr(value, currLabel.numericFormatter) : SerieLabelHelper.GetFormatterContent(serie, serieData, value, total, - currLabel, color); + currLabel, color, chart); serieData.SetLabelActive(currLabel.show && !isIgnore && !serie.IsMinShowLabelValue(value)); serieData.labelObject.UpdateIcon(currLabel.icon); serieData.labelObject.SetText(content);