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>fill();</code></h3>
  <p>Change the graph colour to any specific colour. Fill can take a colour name, an rgb or an hex value.</p>

  <div> 
    <button class="rs-btn--small rs-btn--selected" 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>

<div>
  <p id='hexInfo'></p>
</div>

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

CSS

              
                #description,#hexInfo {
  margin : 1em;
  
}
button{
  padding: 5px;
}
              
            
!

JS

              
                //RedSift
//Change the graph colour to a specific colour.
//The example shows that fill can take colour name, rgb or hex value. 


let chart = d3_rs_lines.html()
    .fill('red'); //fill graph to the colour red 

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

  d3.select('#hexInfo')
    .html("The graph is filled using colour name <code>fill('red')</code>");

function colour() {

  let chart = d3_rs_lines.html()
    .fill('red'); //fill graph to the colour red

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

  d3.select('#hexInfo')
    .html("The graph is filled using colour name <code>fill('red')</code>.");
}

function rgb() {
  let chart = d3_rs_lines.html()
    .fill('rgb(0,0,259)'); //rgb value set to blue colour

  d3.select('#chart').datum([1, 2, 3, 10, 20])
    .call(chart);
  d3.select('#hexInfo')
    .html("The graph is filled using rgb value <code>fill('rgb(0,0,259)')</code> representing blue colour.");
}

function hex() {
  let chart = d3_rs_lines.html()
    .fill('#99ff33'); //hex value set to green

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

  d3.select('#hexInfo')
    .html("The graph is filled using hex value <code>fill('#99ff33')</code> representing green colour.");
}

// 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