0

I have a prolem with chartjs. My current chart is ( label is corresponding to the data value )

current char

How can i create like this label (it has a range of values 1950 1955 1960 1965 ..)

chart-I-want

This is my code

   var ctx = document.getElementById('myChart').getContext('2d');

  var myChart = new Chart(ctx, {
    type: 'line',
    data: {
      labels: label,
      datasets: [
        {
          label: "Tempt",
          fill: true,
          backgroundColor: 'rgb(190, 99, 255, 0.25)',
          borderColor: 'rgb(190, 99, 255)',
          data: Tempt,
        },
        {
          label: "Hum",
          fill: false,
          backgroundColor: 'rgba(255, 99, 132, 0.25)',
          borderColor: 'rgb(255, 99, 132)',
          data: Hum,
        }
      ]
    }
  }
  );
Vincent
  • 1
  • 1
  • 2
  • What you show as expected chart is clearly a bar chart. The first step to achieve such a result would be to change `type: 'line',` into `type: 'bar',` – uminder Jul 19 '20 at 19:24
  • i want my x axis like label has a range of values same of chart bellow. its like 1950 1955 1960 1965 ... – Vincent Jul 19 '20 at 19:29
  • So something like [this](https://stackoverflow.com/questions/22064577/limit-labels-number-on-chart-js-line-chart#comment60511047_26183983)? – Martin M. Jul 20 '20 at 06:53
  • The easiest way is to change `step-size` to `5`. https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#step-size. Anyway, your data is missing from the Q (its hard to give you a specific answer). – Ezra Siton Jul 20 '20 at 12:12
  • Yes. Thanks. i follow @MartinM. link add opotion xAxes-ticks and its work. – Vincent Jul 20 '20 at 12:48

0 Answers0