Change label color in c3js (c3.js)
I have a very simple c3js pie chart, but the white labels get lost inside the yellow slice of the pie (hast to be that color). Is there any way to change the color of just that label? Alternatively, is there a way to change the color of all labels?
var chart = c3.generate({
data: {
columns: [
['PC', 25077394],
["Tablet", 3240595],
["Mobile", 6427981],
],
type : 'pie'
},
legend: {
position: 'bottom'
},
axis: {
x: {
label: 'Sepal.Width'
},
y: {
label: 'Petal.Width'
}
},
});
setTimeout(function () {
chart.data.colors({PC: '#2C9AB7',Tablet: '#FEBE12', Mobile: '#DB3A1B'});
}, 1000);
javascript css c3.js
add a comment |
I have a very simple c3js pie chart, but the white labels get lost inside the yellow slice of the pie (hast to be that color). Is there any way to change the color of just that label? Alternatively, is there a way to change the color of all labels?
var chart = c3.generate({
data: {
columns: [
['PC', 25077394],
["Tablet", 3240595],
["Mobile", 6427981],
],
type : 'pie'
},
legend: {
position: 'bottom'
},
axis: {
x: {
label: 'Sepal.Width'
},
y: {
label: 'Petal.Width'
}
},
});
setTimeout(function () {
chart.data.colors({PC: '#2C9AB7',Tablet: '#FEBE12', Mobile: '#DB3A1B'});
}, 1000);
javascript css c3.js
add a comment |
I have a very simple c3js pie chart, but the white labels get lost inside the yellow slice of the pie (hast to be that color). Is there any way to change the color of just that label? Alternatively, is there a way to change the color of all labels?
var chart = c3.generate({
data: {
columns: [
['PC', 25077394],
["Tablet", 3240595],
["Mobile", 6427981],
],
type : 'pie'
},
legend: {
position: 'bottom'
},
axis: {
x: {
label: 'Sepal.Width'
},
y: {
label: 'Petal.Width'
}
},
});
setTimeout(function () {
chart.data.colors({PC: '#2C9AB7',Tablet: '#FEBE12', Mobile: '#DB3A1B'});
}, 1000);
javascript css c3.js
I have a very simple c3js pie chart, but the white labels get lost inside the yellow slice of the pie (hast to be that color). Is there any way to change the color of just that label? Alternatively, is there a way to change the color of all labels?
var chart = c3.generate({
data: {
columns: [
['PC', 25077394],
["Tablet", 3240595],
["Mobile", 6427981],
],
type : 'pie'
},
legend: {
position: 'bottom'
},
axis: {
x: {
label: 'Sepal.Width'
},
y: {
label: 'Petal.Width'
}
},
});
setTimeout(function () {
chart.data.colors({PC: '#2C9AB7',Tablet: '#FEBE12', Mobile: '#DB3A1B'});
}, 1000);
javascript css c3.js
javascript css c3.js
asked Sep 16 '14 at 15:58
neelshivneelshiv
1,60031325
1,60031325
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can do it with css;
To only change the yellow one you could declare the following class:
.c3-target-Tablet text {
fill: black;
}
to paint them all in black you can do something as this (consider refining it if you don't want it to apply to every chart!):
.c3-chart-arc text {
fill: black;
}
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
add a comment |
The css code below was helpful for me in such a case:
.c3-chart-arc text {
fill: black !important;
}
add a comment |
You can also change the colors using D3.
for example:
d3.select(".c3-target-PC > text").style("fill",#2C9AB7);
you could also use an array of colors:
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
d3.select(".c3-target-"+colors[0][0]+" + " > text").style("fill",colors[0][1]);
or even use a loop...
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
for(var i = 0; i < colors.length; i++){
d3.select(".c3-target-"+colors[i][0]+" > text").style("fill",colors[i][1]);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25873398%2fchange-label-color-in-c3js-c3-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it with css;
To only change the yellow one you could declare the following class:
.c3-target-Tablet text {
fill: black;
}
to paint them all in black you can do something as this (consider refining it if you don't want it to apply to every chart!):
.c3-chart-arc text {
fill: black;
}
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
add a comment |
You can do it with css;
To only change the yellow one you could declare the following class:
.c3-target-Tablet text {
fill: black;
}
to paint them all in black you can do something as this (consider refining it if you don't want it to apply to every chart!):
.c3-chart-arc text {
fill: black;
}
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
add a comment |
You can do it with css;
To only change the yellow one you could declare the following class:
.c3-target-Tablet text {
fill: black;
}
to paint them all in black you can do something as this (consider refining it if you don't want it to apply to every chart!):
.c3-chart-arc text {
fill: black;
}
You can do it with css;
To only change the yellow one you could declare the following class:
.c3-target-Tablet text {
fill: black;
}
to paint them all in black you can do something as this (consider refining it if you don't want it to apply to every chart!):
.c3-chart-arc text {
fill: black;
}
answered Nov 7 '14 at 23:15
Sebastian PiuSebastian Piu
6,4222346
6,4222346
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
add a comment |
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
Thanks! This worked like a charm. I just didn't know what class to apply the rules to before.
– neelshiv
Nov 24 '14 at 16:29
add a comment |
The css code below was helpful for me in such a case:
.c3-chart-arc text {
fill: black !important;
}
add a comment |
The css code below was helpful for me in such a case:
.c3-chart-arc text {
fill: black !important;
}
add a comment |
The css code below was helpful for me in such a case:
.c3-chart-arc text {
fill: black !important;
}
The css code below was helpful for me in such a case:
.c3-chart-arc text {
fill: black !important;
}
answered Apr 12 '18 at 8:17
Margaryta ViterMargaryta Viter
1
1
add a comment |
add a comment |
You can also change the colors using D3.
for example:
d3.select(".c3-target-PC > text").style("fill",#2C9AB7);
you could also use an array of colors:
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
d3.select(".c3-target-"+colors[0][0]+" + " > text").style("fill",colors[0][1]);
or even use a loop...
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
for(var i = 0; i < colors.length; i++){
d3.select(".c3-target-"+colors[i][0]+" > text").style("fill",colors[i][1]);
}
add a comment |
You can also change the colors using D3.
for example:
d3.select(".c3-target-PC > text").style("fill",#2C9AB7);
you could also use an array of colors:
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
d3.select(".c3-target-"+colors[0][0]+" + " > text").style("fill",colors[0][1]);
or even use a loop...
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
for(var i = 0; i < colors.length; i++){
d3.select(".c3-target-"+colors[i][0]+" > text").style("fill",colors[i][1]);
}
add a comment |
You can also change the colors using D3.
for example:
d3.select(".c3-target-PC > text").style("fill",#2C9AB7);
you could also use an array of colors:
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
d3.select(".c3-target-"+colors[0][0]+" + " > text").style("fill",colors[0][1]);
or even use a loop...
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
for(var i = 0; i < colors.length; i++){
d3.select(".c3-target-"+colors[i][0]+" > text").style("fill",colors[i][1]);
}
You can also change the colors using D3.
for example:
d3.select(".c3-target-PC > text").style("fill",#2C9AB7);
you could also use an array of colors:
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
d3.select(".c3-target-"+colors[0][0]+" + " > text").style("fill",colors[0][1]);
or even use a loop...
var colors = [['PC','#2C9AB7'],['Table','#FEBE12'],['Mobil','#DB3A1B']];
for(var i = 0; i < colors.length; i++){
d3.select(".c3-target-"+colors[i][0]+" > text").style("fill",colors[i][1]);
}
edited Nov 22 '18 at 13:36
Kvam
1,8481317
1,8481317
answered Nov 22 '18 at 13:10
gothmogggothmogg
226
226
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25873398%2fchange-label-color-in-c3js-c3-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown