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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h1>JS Charts</h1>

<div id="charts">
</div>

<div id="input-container">
</div>

<div id="add-bar-inputs">
  <input type="text" placeholder="name..." name="chartbar-name">
  <input type="text" placeholder="percentage..." name="chartbar-need">
</div>
<div id="add-bar-button-container">
  <button onclick="addChartBar()">ADD BAR TO CHART</button>
</div>
              
            
!

CSS

              
                body {
  background: black;
  font-family: verdana;
  color: white;
}

.chart-item-bar-green {
  background: rgb(0, 104, 12);
  border: 1px solid green;
}

.chart-item-bar-yellow {
  background: rgb(155, 152, 0);
  border: 1px solid yellow;
}

.chart-item-bar-red {
  background: rgb(155, 15, 0);
  border: 1px solid red;  
}

#charts {
  display: grid;
  grid-template-columns: 200px auto;
  grid-gap: 10px;
  max-width: 1500px;
  margin: 0 auto;
}

#charts > span {
  text-align: right;
  align-self: center;
  color: grey
}

#charts > div {
  border-width: 1px 1px 1px 0;
  height: 30px;
}

h1 {
  text-align: center;
  font-size: 3em;
}

#input-container {
  padding-top: 50px;
  max-width: 1500px;
  margin: 0 auto;
  color: white;
  
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

#input-container h3 {
  margin: 5px;
  text-align: center;
}

#input-container > div {
  display: flex;
  flex-direction: column;
  display: inline-block;
    
  border-radius: 2px;
  margin: 20px;
  padding: 15px;
}

#input-container div div {
  display: flex;
  justify-content: space-between;
}

#add-bar-inputs {
  display: flex;
  max-width: 900px;
  justify-content: center;
  margin: 0 auto;
  perspective: 100px;  
}

#add-bar-inputs input {
  background: black;
  color: white;
  border: 0;
  border-bottom: 1px solid white;
  height: 20px;
  width: 120px;
  padding: 10px;
  font-size: 1em;
  margin: 10px;
  
  transition: .25s;
}

#add-bar-button-container {
  display: flex;
  justify-content: center;
  perspective: 100px;
}

#add-bar-button-container button {
  background: #2570ea;
  color: white;
  border: 0;
  font-size: 1em;
  padding: 15px;
  cursor: pointer;
  
  transition: .25s;
}

#add-bar-button-container button:focus, #add-bar-button-container button:hover, #add-bar-inputs input:focus {
  transform: translateZ(1em);
  transition: .5s;
}

button:focus, input:focus {
  outline: 0;
}
              
            
!

JS

              
                //create roles object
const roles = [
	{ role: '3D Artist', need: 1 },
  { role: 'AI Programmer', need: 1 },
  { role: 'PR Supervisor', need: 0.8 },
  { role: '3D Animator', need: 0.7 },
  { role: 'Concept Art', need: 0.6 },
  { role: 'Programming', need: 0.5 },
  { role: 'Level Designer', need: 0.4 },
  { role: 'Musician', need: 0.3 },
  { role: 'Voice Actor/Actress', need: 0.2 },
  { role: 'Writer', need: 0.1 },
  { role: 'Playtester', need: 0.1 }
];

function createCharts() {
  roles.sort((a, b) => b.need - a.need);

  const charts = document.getElementById('charts');

  for (const role of roles) {
    const span = document.createElement('span');
    span.innerText = role.role;

    const div = document.createElement("div");
    div.style.width = role.need*100 + '%';

    if (role.need <= 1 && role.need >= 0.8) {
      div.className = 'chart-item-bar-green';  
    } else if (role.need >= 0.5) {
      div.className = 'chart-item-bar-yellow';
    } else {
      div.className = 'chart-item-bar-red';
    }
    
    //delete line when right clicking
    div.setAttribute('oncontextmenu', `deleteChartBar('${role.role}')`);

    charts.appendChild(span);
    charts.appendChild(div);
  }
}
createCharts();


//START CUSTOM INPUTS
function createInputs() {
  const inputs = document.getElementById('input-container');

  for (const role of roles) {
    const mainDiv = document.createElement('div');

    //add appropriate class based on percentage
    if (role.need <= 1 && role.need >= 0.8) {
      mainDiv.className = 'chart-item-bar-green';  
    } else if (role.need >= 0.5) {
     mainDiv.className = 'chart-item-bar-yellow';
    } else {
      mainDiv.className = 'chart-item-bar-red';
    }

    const title = document.createElement('h3');
    title.innerText = role.role + ' - ' + role.need*100 + '%';
    mainDiv.appendChild(title);

    const inputContainer = document.createElement('div');
    const min = document.createElement('h3');
    min.innerText = '0%';
    const max = document.createElement('h3');
    max.innerText = '100%';

    const input = document.createElement('input');
    input.setAttribute('type', 'range');
    input.setAttribute('min', 0);
    input.setAttribute('max', 1);
    input.setAttribute('step', .01);  
    input.setAttribute('value', role.need);
    input.addEventListener('input', e => {
      //getting h3 title of input and changing percentage
      let textTitle = e.target.parentElement.parentElement.firstChild.innerText;
      textTitle = textTitle.substr(0, textTitle.indexOf(' -'));
      e.target.parentElement.parentElement.firstChild.innerText = textTitle + ' - ' + ~~(e.target.value * 100) + '%';

      //find associated role and change its value to match input
      for (const thing of roles) {
        if (thing.role === textTitle) {
          thing.need = e.target.value
          document.getElementById('charts').innerHTML = '';
          createCharts();

          //add appropriate class based on percentage
          if (thing.need <= 1 && thing.need >= 0.8) {
            e.target.parentElement.parentElement.className = 'chart-item-bar-green';  
          } else if (thing.need >= 0.5) {
            e.target.parentElement.parentElement.className = 'chart-item-bar-yellow';
          } else {
            e.target.parentElement.parentElement.className = 'chart-item-bar-red';
          }
        }
      }


    });

    inputContainer.appendChild(min);
    inputContainer.appendChild(input);
    inputContainer.appendChild(max);  

    mainDiv.appendChild(inputContainer);

    inputs.appendChild(mainDiv);
  }
}
createInputs();

//start function for deleting entries
function deleteChartBar(role) {
  for (let i = 0; i < roles.length; i++) {
    if (roles[i].role === role) {
      roles.splice(i, 1);
      i--;
    }
  }
  
  document.getElementById('charts').innerHTML = '';
  createCharts();
  document.getElementById('input-container').innerHTML = '';
  createInputs();
}

//start input to add entries
function addChartBar() {
  const role = document.getElementsByName('chartbar-name')[0].value;
  let need = parseFloat(document.getElementsByName('chartbar-need')[0].value);
  
  if (!isNaN(need) && need <= 100) {
    document.getElementsByName('chartbar-name')[0].value = '';
    document.getElementsByName('chartbar-need')[0].value = '';

    //if greater than 1, user probably thought about percentages, so make it into decimal
    need = need > 1 ? need/100 : need;

    roles.push({role, need});

    document.getElementById('charts').innerHTML = '';
    createCharts();
    document.getElementById('input-container').innerHTML = '';
    createInputs();
  } else {
    document.getElementsByName('chartbar-need')[0].value = '';
  }
}
              
            
!
999px

Console