Change label color in c3js (c3.js)












2















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);









share|improve this question



























    2















    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);









    share|improve this question

























      2












      2








      2


      1






      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);









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 16 '14 at 15:58









      neelshivneelshiv

      1,60031325




      1,60031325
























          3 Answers
          3






          active

          oldest

          votes


















          5














          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;
          }





          share|improve this answer
























          • 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



















          0














          The css code below was helpful for me in such a case:



          .c3-chart-arc text {
          fill: black !important;
          }





          share|improve this answer































            0














            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]);
            }





            share|improve this answer

























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              5














              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;
              }





              share|improve this answer
























              • 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
















              5














              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;
              }





              share|improve this answer
























              • 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














              5












              5








              5







              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;
              }





              share|improve this answer













              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;
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              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



















              • 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













              0














              The css code below was helpful for me in such a case:



              .c3-chart-arc text {
              fill: black !important;
              }





              share|improve this answer




























                0














                The css code below was helpful for me in such a case:



                .c3-chart-arc text {
                fill: black !important;
                }





                share|improve this answer


























                  0












                  0








                  0







                  The css code below was helpful for me in such a case:



                  .c3-chart-arc text {
                  fill: black !important;
                  }





                  share|improve this answer













                  The css code below was helpful for me in such a case:



                  .c3-chart-arc text {
                  fill: black !important;
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 12 '18 at 8:17









                  Margaryta ViterMargaryta Viter

                  1




                  1























                      0














                      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]);
                      }





                      share|improve this answer






























                        0














                        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]);
                        }





                        share|improve this answer




























                          0












                          0








                          0







                          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]);
                          }





                          share|improve this answer















                          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]);
                          }






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 22 '18 at 13:36









                          Kvam

                          1,8481317




                          1,8481317










                          answered Nov 22 '18 at 13:10









                          gothmogggothmogg

                          226




                          226






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                              Alcedinidae

                              Can an atomic nucleus contain both particles and antiparticles? [duplicate]