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.

Setting xAxes type to linear causes line chart to not be drawn

See original GitHub issue

I have the following simple line chart:

<canvas id="myChart"></canvas>

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'line',
    data: {
        datasets: [{
            label: "My First dataset",
            data: [1, 2, 3, 20],
        }],
        labels: [1, 2, 10, 20],
    },
    options: {
    	scales: {
      	xAxes: [{
          display: true,
          type: 'linear',
          position: 'bottom',
          ticks: {
          	min: 0,
            stepSize: 1
          }
        }],
      }
    }
});

Whenever the xAxes type is set to linear, the line chart is no longer drawn within the chart. Here is a fiddle showing the issue. I am using the latest version, 2.6.0.

I have looked on SO and through the issues reported but haven’t found a way to get this to work.

Thanks in advance for your assistance.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mschekercommented, Aug 23, 2017

@etimberg Thank you for your response. If I have data as follows:

data: {
        datasets: [{
            label: "My First dataset",
            data: [1, 2, 3, 20],
        }],
        labels: [1, 2, 10, 20],
    },

Is there a way to set the axis’ stepSize so it displays the ticks from min to max (0-20 - based on the labels), for example? If not, I’ll try to change the dataset if need be.

Thanks again.

0reactions
ravenasycommented, Nov 11, 2020

if i use solution etimberg , i have probleme type

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart.js xAxis linear scale : strange behavior - Stack Overflow
This just draws a vertical line for me... and the linked page shows completely different code, without {x,y} objects in data. – riv....
Read more >
Linear Axis - Chart.js
The linear scale is used to chart numerical data. It can be placed on either the x or y-axis. The scatter chart type...
Read more >
Change the scale of the horizontal (category) axis in a chart
How to change the scale of the horizontal or X) axis of a chart. ... based on data determines the axis type that...
Read more >
Creating chart in Excel where data for X-axis (horizontal) is ...
What I'd like to do with MS-Excel is to plot 2 curves, one that treats values in col. 'X' as horizontal axis data,...
Read more >
Line chart options | Looker - Google Cloud
Overview of visualization menu options for line charts. ... charts with various measure types so long as they are not combined (such as...
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