You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "hughess (via GitHub)" <gi...@apache.org> on 2023/05/13 21:44:18 UTC

[GitHub] [echarts] hughess opened a new issue, #18622: [Bug] Need y-axis information in params for tooltip formatter

hughess opened a new issue, #18622:
URL: https://github.com/apache/echarts/issues/18622

   ### Version
   
   5.4.2
   
   ### Link to Minimal Reproduction
   
   https://echarts.apache.org/examples/en/editor.html?c=line-smooth&code=DYUwLgBADgTiUgHYBMBiB7GBbAhmAymDAJaIDmAzhALwQDeAUBBAAwBcEARACScA0TCAEYOnQDUEnBgF8GDdFDDF0iGvUEAPAILriFDo2bMwATwQcA5AGM8IMpmPmBhiMjw4OAbXMBZZY4jmACoAriD-5gDqIMjhgQAWweGoJOH4eKnBiOYAuoJSThBg6OjAilD6gkYkZGQgMBY4OhSOlRAAZpi4YGB1HG2ZlorKABRQODA4WBQAlAbOhqCQ6MFgUCuqnJwA3K3OixDGAGo4wDvzEACQHTAQw_vEqmMTUwB0oORgcRAAtMJbEA8AHy0Fj_Yjfb7TNQXGEwo4nR7jSYUDzEbIvABuJ1CHiE2R2sJhy1W62oDEJRJWa0gAGpyRTzAAeABGMAA9IDzBA6RSLk9kaj0RQ6sQQBQAHKTEDcriiGX8qaCzHYkAvIoAGXQ1lAhBI5GG03pMJk5zgYGCMBUxOprRNEHygmM2l0njmRlMIAsWOAoRaMMaunVOGZIGAFVhFDi6AA7hwiKEBLC4sRkCAAPIYurAHDlQowBNGyMx7yNIMhsN5guw65dHr1doDIYqYbe0JQxiEs0WlTmbhcmkQVuqjVak4gXWkMgGo0O2G4GBkUgcAAs9IdzHXamcJjMASHLWcJ2IZEQgWIlgA1npKyACswAxQy6HwzCi7Gb4mYcnUxmszm4_mt6FlG0YluoT4VvGQHVp0eB1n0jZKM2Q7tkaFxdpaXASDKQ5qugmrauORCTtOsKzjC86LogK5rgUdrZAUwokGKnitG6hiuGA7gQB4AAcABMLB8BAACcADM_HCSJLBCFJYnLsJQj8dJiliWJQnCBJLAMbshQehYwCkGEd6GBQWDFJ8AEFuciBShYiCYJ8EBSiQ1gQBQY7NLaJnMOxzCcdxuICRpQjiZJwjSbJE
 XyYpIkqdFIUAOyCTp5w7p6ASGYgxm6U6TQAJIoCA6hsLJum2VgGXmCAFryNKHmgF5zj0dIWxAA
   
   ### Steps to Reproduce
   
   1. Create a chart with 2 y axes, each with a different number format
   2. Create a tooltip with `trigger: 'axis'` 
   3. Attempt to format each number in the tooltip in the same way as each number's corresponding axis
   
   ### Current Behavior
   
   I can access information about the data using `params`, but this does not include the `yAxisIndex`. Without `yAxisIndex`, I am not able to determine which format to apply to the numbers in the tooltip.
   
   ### Expected Behavior
   
   `params` should include at least `yAxisIndex` since it is a property of the series which is being summarized in the `params`.
   
   Even though with `trigger: 'axis'`, you don't know which series is currently active (i.e. they are all active at once), this information can still be contained in `params` since it can be used to execute iterative logic over the information within `params`.
   
   Alternatively, if there is a way to pass arbitrary information which will appear in `params`, that would solve my problem (e.g., if I could pass a custom column into the series config and retrieve it in the tooltip formatter function through `params`).
   
   ### Environment
   
   ```markdown
   N/A
   ```
   
   
   ### Any additional comments?
   
   The reason I need to figure this out with `trigger: 'axis'` is that tooltips are not really usable with `trigger: 'item'`. Ideally, I could use trigger item to get tooltips displayed for individual series in a chart, but the target hover area is unreasonably small since it relies on symbols, and I typically leave symbols out of my charts for cleanliness of appearance. The only way around this seems to be a custom setup using events, which I would prefer not to do.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org.apache.org

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] [echarts] hughess commented on issue #18622: [Bug] Need y-axis information in params for tooltip formatter

Posted by "hughess (via GitHub)" <gi...@apache.org>.
hughess commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1548622062

   That almost works, but there are cases where we use the same column name for multiple series, which causes an error if inputted into the `seriesId` field.
   
   For example, here's a typical dataset a user would pass into one of our chart components:
   
   ```js
   data = [
      {year: 2010, country: "US", sales_usd: 100, orders_num: 50},
      {year: 2011, country: "US", sales_usd: 100, orders_num: 50},
      {year: 2010, country: "UK", sales_usd: 100, orders_num: 50},
      {year: 2011, country: "UK", sales_usd: 100, orders_num: 50},
      {year: 2010, country: "China", sales_usd: 100, orders_num: 50},
      {year: 2011, country: "China", sales_usd: 100, orders_num: 50}
   ]
   ```
   
   The user would supply these columns using these options in our API:
   ```js
   x=year
   y=sales_usd
   y2=orders_num
   series=country
   ```
   
   And then we map them to individual series names that will look like this:
   - "US - Sales ($)"
   - "US - Orders"
   - "UK - Sales ($)"
   - "UK - Orders"
   - "China - Sales ($)"
   - "China - Orders"
   
   So in the example of a line chart, this would generate 6 lines/series, without an easy way to get back to the column id through `params` in the tooltip.
   
   Worst case, I could parse the `seriesName` to reverse engineer which column it came from (or check if the formatted column name is within the seriesName), but that feels like an error-prone solution.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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] [echarts] hughess commented on issue #18622: [Bug] Need y-axis information in params for tooltip formatter

Posted by "hughess (via GitHub)" <gi...@apache.org>.
hughess commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1546880350

   Sorry, my example doesn’t do a great job of showing the problem. The reason I can’t use the series to determine the format is I’m building a library on top of echarts, so I need to create a generalized formatter function that can be used in any situation. For the axis labels, I have access to the series information before generating the chart, so I can supply the formatting that the user sets for each column. 
   
   Unfortunately, for tooltips I can’t access that same information because it’s triggered from the client.
   
   I might be able to use the series name to look up what the correct format is, but there is one other issue with that: we show our series names as formatted versions of column names (e.g., sales_usd —-> Sales ($) ). Ideally, I would look up the format using the series column name (sales_usd), but the only information I have access to in params is the formatted name. I haven’t been able to figure out how to set a separate series name and ID in a way that will be accessible in the tooltip formatter.
   
   For reference, here is the feature I am looking to implement where this is an issue: 
   https://github.com/evidence-dev/evidence/issues/412


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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


Re: [I] [Bug] Need y-axis information in params for tooltip formatter [echarts]

Posted by "hughess (via GitHub)" <gi...@apache.org>.
hughess commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1745153557

   @helgasoft I'm looking at this again after this feature got deprioritized behind some other things. Thanks for getting back to me.
   
   Prefixing the column seems like a complicated solution and would interfere with our column formatting logic (we take the column name and present it as a nicely formatted title in the chart).
   
   I tried another solution which almost worked, which I'll describe below:
   - I created a variable to count the number of series on the y axis vs. on the secondary y axis
   - I used `componentIndex` within `params` to see which axis each series should be on (e.g., if `componentIndex < ySeriesCount` then it's on the first axis, otherwise on the second)
   - This works in the basic case
   - This doesn't work in the case I mentioned above with US/UK/China and Sales/Orders. Here is how the `componentIndex` was set for those:
      -  "US - Sales ($)" `componentIndex: 0`
      - "US - Orders" `componentIndex: 1`
      - "UK - Sales ($)" `componentIndex: 2`
      - "UK - Orders" `componentIndex: 3`
      - "China - Sales ($)" `componentIndex: 4`
      - "China - Orders" `componentIndex: 5`
   - This gave me $ formatting on `0`, `1`, and `2` and # formatting on the other 3
   
   This would all be much easier if I knew `yAxisIndex` in `params`! 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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


Re: [I] [Bug] Need y-axis information in params for tooltip formatter [echarts]

Posted by "hughess (via GitHub)" <gi...@apache.org>.
hughess commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1745229668

   I may have found an approach that works - I've created a function that will take the `componentIndex` plus the count of variables on the first and second y axes, and will return which axis the datapoint should be on. This will work if the order of the series is always y first, then secondary y. In my example above, here's what it will return:
   - "US - Sales ($)" `componentIndex: 0` = `y`
   - "US - Orders" `componentIndex: 1` = `y2`
   - "UK - Sales ($)" `componentIndex: 2` = `y`
   - "UK - Orders" `componentIndex: 3` = `y2`
   - "China - Sales ($)" `componentIndex: 4` = `y`
   - "China - Orders" `componentIndex: 5` = `y2`


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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] [echarts] helgasoft commented on issue #18622: [Bug] Need y-axis information in params for tooltip formatter

Posted by "helgasoft (via GitHub)" <gi...@apache.org>.
helgasoft commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1546796104

   Series data determines the format. I don't see the need for _yAxisIndex_.
   "north america" :fast_forward: params[i].seriesIndex==0 :fast_forward: format $
   "europe"            :fast_forward: params[i].seriesIndex==1 :fast_forward: format €
   
   NB: please close issue if problem solved.
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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] [echarts] helgasoft commented on issue #18622: [Bug] Need y-axis information in params for tooltip formatter

Posted by "helgasoft (via GitHub)" <gi...@apache.org>.
helgasoft commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1546966294

   >  we show our series names as formatted versions of column names (e.g., sales_usd —-> Sales ($) ).
   
   If the _seriesName_ is already used, why not set the column name (sales_usd) as _seriesId_ ? Then the formatting info will be available for tooltip.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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] [echarts] helgasoft commented on issue #18622: [Bug] Need y-axis information in params for tooltip formatter

Posted by "helgasoft (via GitHub)" <gi...@apache.org>.
helgasoft commented on issue #18622:
URL: https://github.com/apache/echarts/issues/18622#issuecomment-1548687390

   > there are cases where we use the same column name for multiple series, which causes an error if inputted into the **seriesId** field
   
   Is there a problem to prefix the column name with a counter value ('99sales_usd') or another column ('UKsales_usd') to make it **unique** ? For tooltip formatting just the "_usd" part of _seriesId_ will be needed anyway.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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