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.

Zero values skipped on logarithmic scale line chart

See original GitHub issue

Expected Behavior

A line chart should be able to display values of 0 along the bottom axis and the y axis should start at zero if the y scale is logarithmic.

Current Behavior

Values of 0 on a logarithmic scale line chart are not shown on the chart. min:0 and beginAtZero: true both appear to have no effect on the issue that 0 does not appear on the line chart.

This functionality appears to be working in v2. In v3.0.2 it somewhat works by displaying the 0 points at the bottom of the chart, however the scale is still not set to 0.

Steps to Reproduce

https://codepen.io/flesher1/pen/WNORQoQ

Provide a dataset containing 0s. Use a line graph with logarithmic scale. Copying example below:

var ctx = document.getElementById("chart").getContext("2d");
var chart = new Chart(ctx, {
  type: "line",
  data: {
    labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    datasets: [
      {
        backgroundColor: "rgb(75, 192, 192, 0.5)",
        data: [2000, 400, 10, 1, 0, 0.001, 0.5],
      }
    ]
  },
  options: {
    scales: {
      xAxes: [{
        type: 'category'
      }],
      y: {
        type: 'logarithmic',
        beginAtZero: true
      }
    }
  }
});

Context

In this case, I have Data that contains 10s, 20s, 0s, and numbers around 80,000.

Environment

  • Chart.js version: 3.1.0 and newer
  • Browser name and version: Chrome

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kurklecommented, Sep 8, 2021
0reactions
skalimer0commented, Sep 23, 2022

For now, points at 0 are skipped

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highcharts: Displaying zero values in logarithmic scale
I know that log(0) doesn't exist but I need to draw 0 values, and I need a log scale. I read in other...
Read more >
Logarithmic scale with zeros - Nevron Software
The behavior of zero values in log axes primarily targets charts with zero scale origin (like bar), which look "good" when zeros are...
Read more >
Logarithmic Axis - Chart.js
The logarithmic scale is used to chart numerical data. ... logarithmic interpolation is used to determine where a value lies on the axis....
Read more >
Problem with Log Scale type in Line chart
This problem is handled in line graph when Scale type is chosen as "Linear" and Start as "Auto". But the same "Auto" feature...
Read more >
How do I set my axis values down to zero when changing my y ...
There is no zero on log scale. Add one line on the end of your code: Theme.
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