Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

javascript - Chartjs: Multiple data values for the same label

I'm trying to build a chart that looks like this ...

Chart bar example

However I am not able to use multiple data values for the same label. Does anyone have any ideas? I'm using chart.js

I would like the code to look something like this...

labels: ['category 1, 'category 2'],
datasets: [
      {
        // values for category one
        type: 'bar',
        backgroundColor: '#8e5ea2',
        data: [111, 222, 333]
      }, {
        // values for category two
        type: 'bar',
        backgroundColor: '#3e95cd',
        data: [111, 222, 333]
      }
    ]

However, chart.js takes each data item for each label created. I would like to have multiple date items for just one label

question from:https://stackoverflow.com/questions/65713143/chartjs-multiple-data-values-for-the-same-label

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure if it will work but you can try to specify the data as an object and then in the first dataset put all the x values to the first label and in the second dataset put all the x values to the second label. https://www.chartjs.org/docs/master/general/data-structures


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...