You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2020/06/03 13:27:05 UTC

[GitHub] [incubator-echarts] dvago opened a new issue #12749: Missing Label formatter control of the single variables format

dvago opened a new issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749


   ### What problem does this feature solve?
   The current interface to control labels within the charts is giving the user the possibility to define what content to display and in which order to print, however it is missing the possibility (or it's not that clear) to set a specific format for the variables.
   
   So imagine the chart displays a series of labels (e.g. AVG, MIN, MAX) see the screenshot:
   ![Screenshot 2020-06-03 at 14 19 00](https://user-images.githubusercontent.com/5074033/83641291-3d02c500-a5a5-11ea-8960-30319672a483.png)
   
   the markPoint set up has a custom formatter which is:
   
   ```
    markPoint: {
                   label: {
                       formatter: '{b}\n{c}',
                    }
   ```
   
   However I would like to be able to control the value `{c}` in order to display consistent decimal places (e.g. 0.00) 
   
   Ref. from documentation.
   ```Data label formatter, which supports string template and callback function. In either form, \n is supported to represent a new line.
   
   String template
   
   Model variation includes:
   
   {a}: series name.
   {b}: the name of a data item.
   {c}: the value of a data item.
   {@xxx}: the value of a dimension named'xxx', for example,{@product}refers the value of'product'` dimension.
   {@[n]}: the value of a dimension at the index ofn, for example,{@[3]}` refers the value at dimensions[3].
   ``` 
   
   ### What does the proposed API look like?
   I would imagine something within the brackets to control the single value. e.g. `{c:0.0}` where 0.0 could be a series of supported format code, perhaps using the Excel format code convention (https://support.microsoft.com/en-gb/office/number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68?ui=en-us&rs=en-gb&ad=gb) so the developer is able to control numbers and dates 
   
   e.g. `{c:0.00}` where 0.00 is the number format (a number with 2 decimal places).
   
   <!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
   <!-- This issue is in English. DO NOT REMOVE -->


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-643175216


   That seems like https://vuejs.org/v2/guide/filters.html, which provide the possiblity to define filters that can be used to apply common text formatting. I appreciate it very much!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-640330366


   @Ovilia I suppose he means the params in callback of `markPoint` is like `{ value: 120 }` but the params in callback of `yAxis` is just a straight value(but not an object like `markPoint`), they are different about the returned params in their own callback.
   If not using callback, I think he may need a precision to format value simply like https://echarts.apache.org/en/option.html#series-line.markLine.precision


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] dvago commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
dvago commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-643335236


   @Ovilia I found a third different the argument type in the main tooltip attribute, just to let you know (https://echarts.apache.org/en/option.html#series-line.tooltip)
   
   In this case the formatter comes out as an array with an object and you cant use ` \n` but you can plug html tags in it.
   
   ```
   tooltip: {
             formatter: (params) => {
               return `${params[0].name}<br />${params[0].marker}${params[0].data.toFixed(2)}`
             },
    },```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] Ovilia commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
Ovilia commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-643169200


   We are considering providing *pipes* like `formatter: "{b}\n{c | fixed(2)}"` and provide some utility functions. But we haven't reached solid conclusions.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-638224627


   Why not using formatter callback function? I think it's easy to fetch each data parameter and you can return a formatted value what you want.
   https://echarts.apache.org/en/option.html#series-line.markPoint.label.formatter


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-640330366


   @Ovilia I suppose he means the params in callback of `markPoint` is like `{ value: 120 }` but the params in callback of `yAxis` is just a straight value(but not an object like `markPoint`), they are diffrent about the returned params in their own callback.
   If not using callback, I think he may need a precision to format value simply like https://echarts.apache.org/en/option.html#series-line.markLine.precision


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-638224627


   Why not using formatter callback function? I think it's easy to fetch each data parameter and you can return a formatted value you need.
   https://echarts.apache.org/en/option.html#series-line.markPoint.label.formatter


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] Ovilia commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
Ovilia commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-640327109


   @dvago Hi. Can you be more specific on "returns the value straight away therefore params has a different type"? What does that mean?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] plainheart edited a comment on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
plainheart edited a comment on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-643175216


   That seems like https://vuejs.org/v2/guide/filters.html, which provides the possiblity to define filters that can be used to apply common text formatting. I appreciate it very much!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] dvago commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
dvago commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-638243376


   Thanks @plainheart it looks a good solution, however I just want to flag something related to the callback you suggested.
   
   Whenever you use the formatter callback within the `MarkPoint` label object the callback params contain an object with keys like `{ value: 120 }` but the same formatter callback inside the `axisLabel` (e.g. in yAxis) returns the value straight away therefore params has a different type, maybe could be worth to have consistency within this function.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[GitHub] [incubator-echarts] dvago commented on issue #12749: Missing Label formatter control of the single variables format

Posted by GitBox <gi...@apache.org>.
dvago commented on issue #12749:
URL: https://github.com/apache/incubator-echarts/issues/12749#issuecomment-640445479


   Thanks @plainheart, it's exactly what I was pointing out. 
   
   @Ovilia given multiple objects around the chart are using the same naming convention (`label.formatter`) I would suggest to keep the type of returned values within callbacks the same to keep consistency and permit the developer user to share functions across all the objects (e.g. Markpoint, axisLabel). 
   
   e.g. 
   ```
   formatter: () => { 
     // always returns either an Object { value: } or a String/Number 
   }
   ```
   I would  suggest to return an object so you can use keys for the MarkPoint like `name` like this:
   ```
   formatter: params => {
     return `${params.name}\n${params.value?.toFixed(2)}`
   }
   ```
   
   However, the callback solution mentioned by @plainheart solves my request, I just kept the issue open as I believe it would be an "enhancement" the above.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org