Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='description'>
  <h3><code>background();</code></h3>

  <p>Change the background of the graph to any specific colour. The background colour take colour name, rgb or hex value as argument.</p>

  <div>
    <button class='rs-btn--small rs-btn--selected' onclick='_default()'>Default</button></div>
    <button class='rs-btn--small' onclick='colour()'>Colour name</button>
    <button class='rs-btn--small' onclick='rgb()'>RGB colour</button>
    <button class='rs-btn--small' onclick='hex()'>Hex colour</button>
</div>

<div id='chart'></div>

<div id='graphInfo'></div>

</div>
              
            
!

CSS

              
                #description, #chart, #graphInfo{
  margin: 1em;
}
              
            
!

JS

              
                //RedSift
//background();
//graph background colour
//The background colour can be changed to any colour using colour name, rgb or hex value.
//Below shows different ways to change the background parameter 


let chart = d3_rs_lines.html();

d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart); //no background property, by default it is set to white.

d3.select('#graphInfo').html('The graph above has default background colour set to "white".'); //graph info

function colour() {
  let chart = d3_rs_lines.html().background('grey');  //background colour set to grey

  d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart); 

  d3.select('#graphInfo').html('<p>The graph background colour is set to "grey", <code>.background("grey");</code></p>'); //graph info
}

function rgb() {
  let chart = d3_rs_lines.html().background('rgb(0,259,0)'); //rgb value representing the green colour.

  d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart);

  d3.select('#graphInfo').html('<p>The background is set to rgb value of "green" represented by <code>.background("rgb(0,259,0)");</code></p>'); //graph info
}

function hex() {
  let chart = d3_rs_lines.html().background('	#0000ff');  //hex value representing the blue colour

  d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart);

  d3.select('#graphInfo').html('<p>The background is set to hex value of "blue" represented by <code>.background("#0000ff");</code></p>.'); //graph info
}

function _default() {
  let chart = d3_rs_lines.html();

  d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart); //by default background is set to white

  d3.select('#graphInfo').html('The graph above has default background colour set to "white".'); //graph info
}


// Generic function to toggle selected state of a button
d3.selectAll('button')
  .on('click', function() {
    let selected = this;
    d3.selectAll('button')
      .classed('rs-btn--selected', function() {
        return (selected === this);
      });
  });
              
            
!
999px

Console