CSS level bar chart

by jorgeluis

HTML

<div id="app">
  <threerows></threerows>
</div>

<template id="threerows">
  <dl>
    <dt>&gt; 7 days</dt>
    <dd class="is-success">
      <span 
        v-bind:style="{ width: percent(uptimeGood) + '%' }"
        class="bar"></span>
      <span>{{percent(uptimeGood)}} %</span>
    </dd>

    <dt>1&mdash;7 days</dt>
    <dd class="is-info">
      <span 
        v-bind:style="{ width: percent(uptimeOk) + '%' }"
        class="bar"></span>
      <span>{{percent(uptimeOk)}} %</span>
    </dd>


    <dt>&lt; 1 day</dt>
    <dd class="is-danger">
      <span 
        v-bind:style="{ width: percent(uptimeBad) + '%' }"
        class="bar"></span>  
      <span>{{percent(uptimeBad)}} %</span> 
    </dd>

  </dl>
</template>

CSS

body {
  font-family: verdana, sans-serif;
}
dl {
  display: flex;
  flex-wrap: wrap;
}
dd, dt {
  margin: 2px;
  padding: 0.75em 0.5em;
}

dt {
  width: 5em;
}
dd {
  position: relative;
  margin-left: auto;
  width: calc(100% - 8em);
  background-color: #FAFBFD;
  border-right: solid 2px #EEEFF1;
}

dd span {
  position: absolute;
}
dd .bar {
  top: 0;
  left: 0;
  bottom: 0;
}
.is-success .bar {
  background-color: #E3F0D2;
  border-left: solid 2px #CAE8B6;
}
.is-info .bar {
  background-color: #C0DBFF;
  border-left: solid 2px #77B1FF;
}
.is-danger .bar {
  background-color: #FCDADF;
  border-left: solid 2px #E41436;
}

JavaScript

Vue.component('threerows', {
  template: '#threerows',
  data: function() {
    return {
      totalDevices: 13418,
      uptimeGood: 8820,
      uptimeOk: 4555,
      uptimeBad: 43
    }
  },
  
  methods: {
    percent: function (level) {
      return Math.ceil(level / this.totalDevices * 100)
    }
  }
})

new Vue({
  el: '#app',
})