简体   繁体   中英

ChartJS How to set x-axis scale

I'm using chartjs and I want to display some data over 12 months. So I've got around 50 datasets but since I've got only 12 labels, the line chart only shows me 12 data points. How can I change the range/scale of the x-axxis so that all values are displayed?

const labels = Utils.months({count: 12});
const data = {
  labels: labels,
  datasets: [{
     label: '1 year',
     data: [65, 59, 80, 81, 56, 55, 40, 55, 90, 100, 33, 34, 55, 12, 33, 55, 23, 66, etc..],
  }]
 }

Can someone help me out?

I assume that the values contained in your data refer to months (ie say 65,59,80,81) refers to Jan?

If that assumption is valid then you just need to use multiple data sets for each label ie

const labels = Utils.months({count: 12});
const data = {
  labels: labels,
  datasets: [{
     datasets: [{
           label: "Jan",
           data: [65, 59, 80, 81]
      }, {
           label: "Feb",
           data: [56, 55, 40, 55, 90]
      }, {
           label: "Mar",
           data: [100, 33, 34, 55]
      }......continued for each months data ...]
  }]
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM