question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using tick callbacks can add extra digits to tick labels

See original GitHub issue

Expected Behavior

Null Y axis tick callback ((value) => value) or simple callback (`(value) => value + ‘psi’) should not affect value precision.

Current Behavior

For some values of data and suggested axis limits, the Y axis ticks are rendered with extraneous digits (e.g. “78.95000000000002” instead of “78.95”) if a callback is present, even if that callback does not change the value it’s passed.

Possible Solution

Might need to add an argument to the callback API that gives the proposed/default string rendering of the number value.

Steps to Reproduce

Set suggestedMin, suggestedMax, and data as shown in example. Set a null callback for the Y axis ticks, and note extra digits in Y axis tick labels. Remove callback, and note change in tick labels.

Context

Our project plots values in engineering units (psi, kPa, V, °C, etc.) logged from our controllers. We use a tick callback to add those units to the Y axis tick labels.

We do not know the range of the data in an individual log in advance, so in order to maximize the dynamic range of the plot, we compute suggestedMin and suggestedMax from the data. In addition, the data may be converted to localized units (e.g. showing °F for US users), which introduces small errors due to FP precision limitations.

Environment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kurklecommented, Dec 15, 2021

That could be a good addition to the documentation.

Further, you can also use the ticks.format to pass options to the default formatter: https://codepen.io/kurkle/pen/gOGmXzK

https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#linear-axis-specific-tick-options

1reaction
kurklecommented, Dec 15, 2021

The number formatting is done in the callback. If you replace the callback, its up to you to make it produce nice ticks.

You can call the default formatter from the callback: https://codepen.io/kurkle/pen/bGoqYEK

Read more comments on GitHub >

github_iconTop Results From Across the Web

Callback Function on Specific Ticks Y axis in Chart JS
Callback Function on Specific Ticks Y axis in Chart JSHow to add callback function on specific ticks on the y- axis in Chart...
Read more >
chart.js - Conditional in ChartJS axes tick callback function isn ...
log(rollingLabel) within the conditional I can see that the variable is updating how I'd expect but it's not returning the value, or it...
Read more >
Setting axes tick labels format - Undocumented Matlab
Matlab plot axes ticks can be customized in a way that will ... callback function to add extra decimals until the labels become...
Read more >
Formatting ticks in Python - Plotly
Detailed examples of Formatting Ticks including changing color, size, log axes, and more in Python.
Read more >
Is it possible to remove only specific tick mark(s) while keeping ...
You can, but if you've customized the labels it's a bit trickier. Ideally you want to change the XTick and XTickLabel properties simultaneously, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found