Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

y2-axis values aren't properly positioned with the ticks #268

Closed
1 of 8 tasks
kczx3 opened this issue Nov 16, 2021 · 1 comment
Closed
1 of 8 tasks

y2-axis values aren't properly positioned with the ticks #268

kczx3 opened this issue Nov 16, 2021 · 1 comment

Comments

@kczx3
Copy link

kczx3 commented Nov 16, 2021

Bug Report

Description

When using a y and y2-axis, some data points on the y2 data set are not properly positioned in relation to the axis' ticks.

Graphs affected

  • Bar graph
  • Bubble graph
  • Gantt chart
  • Line graph
  • Paired result
  • Pie chart
  • Scatter plot
  • Timeline

Steps to Reproduce

  1. Everything is in the CodeSandbox
  2. Click on the data points to see their values.

Link to CodeSandbox

Use this template to reproduce the behavior.

Additional Context / Screenshots

image

Expected Behavior

Data points will be properly positioned vertically such that their vertical position accurately reflects their actual value. Currently, values such as 1 and -4 on the y2-axis of my demo are not properly positioned. Values of 1 appear too high and values of -4 appear too low.

Possible Solution

Environment

  • Component Name and Version: Line Graph v2.18.2
  • Browser Name and Version: Edge 95 and FireFox 94
  • Node/npm Version: [e.g. Node 8/npm 5]: N/A
  • Webpack Version: N/A
  • Operating System and version (desktop or mobile): Windows 10 20H2

@ Mentions

@sdadn
Copy link
Contributor

sdadn commented Nov 19, 2021

Thanks for the issue. I would like to clarify a few things. Both the axis and and datapoint values are actually correct. What happens is by default, the displayed values of the axes are formatted to be whole numbers. So essentially the values are rounded up to the nearest multiple of 2, 5 or 10 by the underlying D3.js library. If you set the formatting to be a float, you'll get the following:

....
      "y2": {
          "show": true,
          "label": "Score",
          "lowerLimit": -4,
          "upperLimit": 1,
          // to change the display format for ticks:
          ticks: {
              format: "0.1f"
          }
      }
...

CleanShot 2021-11-19 at 13 11 21@2x

Based on the actual numerical value of the axis ticks, the datapoints seem to be positioned correctly, demonstrated below using custom tick values:

CleanShot 2021-11-19 at 13 20 58@2x

Carbon has multiple avenues to mitigate the mismatch between tick values and their rendering:

  • Update the formatting to show decimal points
  • Update the axis limits so that the divisions are multiples of 2, 5 or 10. The allowCalibrate property can be turned off to prevent the limits from auto updating when datapoints >= limit values.
  • Use the ticksCount property for a custom number of divisions.
  • Use custom tick values. However, with this, the responsibility for alignment of the ticks and grid is up to the consumer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants