Giter VIP home page Giter VIP logo

d3-population-pyramid's Introduction

D3-Population-Pyramid

Interactive D3 Population Pyramid in D3 v4. You'll need only popPyramid.min.js and D3 for your own implementation. The easiest use is to include this in your header:

<script src="popPyramid.min.js"></script>

And include something like this in your body:

<script>
  // data must be in a format with age, male, and female in each object
  var exampleData = [{ age: '0-9', male: 10, female: 12 }, { age: '10-19',
  male: 14, female: 15 }, { age: '20-29', male: 15, female: 18 }, { age:
    '30-39', male: 18, female: 18 }, { age: '40-49', male: 21, female: 22 }, {
      age: '50-59', male: 19, female: 24 }, { age: '60-69', male: 15, female: 14 }, {
        age: '70-79', male: 8, female: 10 }, { age: '80-89', male: 4, female: 5 }, {
          age: '90+', male: 2, female: 3 }];

  pyramidBuilder(exampleData, '#pyramid', {height: 400, width: 500});
</script>

What's it look like?

The chart (with default css) looks something like this:

alt text

Options

The function is in the format pyramidBuilder(data, target, options)

Name Type Default Optional Notes
data JSON N/A N Needs age, male, and female properties.
Example: [{ age: '0-50', male: 4500, female: 4500 }, { age: '51-99+',male: 5000, female: 5000 }]
target string N/A N Uses D3's select() function. Examples: '#pyramid', 'body'
options JSON see below N If you want all defaults, you'll need to go with {} for this var
options.height numeric 400 Y
options.width numeric 400 Y
options.style JSON see below Y Example: {leftBarColor: '#00ffaa', rightBarColor: '#ffaa00', tooltipBG: '#333', tooltipColor: 'white'}
options.style.leftBarColor string (hex) '#6c9dc6' Y Input color will be automatically lightened for :hover css
options.style.rightBarColor string (hex) '#de5454' Y Input color will be automatically lightened for :hover css
options.style.tooltipBG string (hex) '#fefefe' Y Uses CSS background property, so you could use more than just a color value.
options.style.tooltipColor string (hex) 'black' Y Controls CSS color property for tooltip

d3-population-pyramid's People

Contributors

doylek avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.