Comments (3)
Hi @y-takey , thanks for your answering.
maybe, you can use a plugin: https://github.com/nagix/chartjs-plugin-colorschemes
I figured out other way to give backgroundColor automatically:
let i = 0;
let color = [];
for (let key in _this.spaceList) {
let x = Math.floor(Math.random() * 255);
let y = Math.floor(Math.random() * 255);
let z = Math.floor(Math.random() * 255);
color.push("rgba(" + x + "," + y + "," + z + ",0.6)");
let type = {
label: key,
data: [_this.spaceList[key]],
backgroundColor: color[i]
}
data.push(type);
i++;
}
I know this isn't a great way, but it's simple and quick, still thanks for your helping!
from chartjs-plugin-stacked100.
Okay, I found this solution
found out there was something I missed in code
getSpace: function () {
let _this = this;
$.getJSON('/dataset/space', function (res) {
_this.spaceList = res;
let data = [];
let color = ["rgba(244, 143, 177, 0.6)", "rgba(255, 235, 59, 0.6)", "rgba(100, 181, 246, 0.6)"];
let i = 0;
for (let key in _this.spaceList) {
let type = {
label: key,
data: _this.spaceList[key], -->here has to be data: [_this.spaceList[key]],
backgroundColor: color[i]
}
data.push(type);
i++;
}
new Chart(document.getElementById("storage"), {
type: "horizontalBar",
data: {
labels: ["空間"],
datasets: data
},
options: {
plugins: {
stacked100: {enable: true}
}
}
});
}
after that, I can print dynamic chart successfully.
But I still have question, can chart.js give backgroundColor
automatically? My datasets would be more and more, is there has any way to give random backgroundColor
that same as the number of datasets?
Thanks
Kase
from chartjs-plugin-stacked100.
Hi @Kesslarr , I'm glad that the issue was solved.
can chart.js give backgroundColor automatically?
maybe, you can use a plugin: https://github.com/nagix/chartjs-plugin-colorschemes
from chartjs-plugin-stacked100.
Related Issues (20)
- Bars are not being displayed with parsing option HOT 11
- Can't load script v1.5.1 on browser. "Uncaught ReferenceError: global is not defined" HOT 1
- staked100 is not working as expected when component re-rendered. HOT 1
- Total percents are bigger then 100% HOT 3
- Could not find a declaration file for module 'chartjs-plugin-stacked100' HOT 8
- stacked100 init HOT 4
- Unable to see labels with percentage as example HOT 3
- Min value is not well calculated HOT 4
- Scale highest bar to 100% HOT 8
- [bug][1.1.0] no types in the npm package HOT 3
- initial dataset.hidden=true doesn't scale visible bars to 100% HOT 1
- [Feature] Stacked group bar + group scale HOT 8
- stacked100 not working with undefined datasets HOT 4
- How to hide zero values ? HOT 2
- Proposal: Option to reduce height HOT 3
- Tooltip not show with percentage as per example HOT 2
- Cannot find module 'chart.js/dist/chunks/helpers.core' or its corresponding type declarations. HOT 3
- ReferenceError: self is not defined HOT 8
- multiple Y axis HOT 4
- Improve type denition of ChartData HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartjs-plugin-stacked100.