0

Chart.js

How do I make my red and blue bars seperate? https://code.sololearn.com/WcvBMchBCCur/?ref=app

31st May 2022, 4:44 PM
Junior
Junior - avatar
9 ответов
+ 5
The x-axis labels are intended for different values within one dataset, the legend labels are intended for different datasets. So there's an easy way to do your chart using x-axis labels and there is an easy way to do it using a legend. I found no easy way of using x-axis labels and legend labels for the same thing. You could probably do it by setting up the legend manually. But I'm not sure it is worth the effort since you'll only end up with redundant information. (The third graph in my code is an illustration of how to use x-axis labels and legend labels for different information.) https://code.sololearn.com/WoAn3YUE90Qd/?ref=app
31st May 2022, 8:54 PM
Simon Sauter
Simon Sauter - avatar
0
Why are you treating the values as separate datasets?
31st May 2022, 5:08 PM
Simon Sauter
Simon Sauter - avatar
0
so i can have more than one legend or label i should say
31st May 2022, 5:09 PM
Junior
Junior - avatar
0
I think your datasets you should be ... data: { labels: [”Italy”, “USA”], datasets: [{ label: “Countries”, data : [20, 30], backgroundColor: [”red”, “blue”] ]} }
31st May 2022, 6:08 PM
Faisal Issaka
Faisal Issaka - avatar
0
data: { labels: ["Italy", "USA"], datasets: [{data: [55, 80], backgroundColor: ["red", "blue"]}] }
31st May 2022, 6:28 PM
Simon Sauter
Simon Sauter - avatar
0
k, thanks but I want 2 of the legend things. One in red for Italy and one blue for USA
31st May 2022, 6:42 PM
Junior
Junior - avatar
0
So i would have only one x-axis?
31st May 2022, 9:06 PM
Junior
Junior - avatar
0
If you really want the legend that's the easy way to do it. Personally I prefer the design with two x-axis labels but no legend.
31st May 2022, 9:12 PM
Simon Sauter
Simon Sauter - avatar
0
ye ye
31st May 2022, 9:14 PM
Junior
Junior - avatar