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="gauge1" class="gauge-container">
    <span class="label">DEFAULT</span>
</div>

<div class="wrapper">
  <div id="gauge2" class="gauge-container two">
    <span class="label">.two</span>
  </div>
</div>

<div id="gauge3" class="gauge-container three">
  <span class="label">.three</span>
</div>

<div id="gauge4" class="gauge-container four">
  <span class="label">.four</span>
  <span class="value-text">km/hr</span>
</div>

<div id="gauge5" class="gauge-container five">
  <span class="label">.five</span>
</div>

<div id="gauge6" class="gauge-container six">
  <span class="label">.six</span>
</div>

<div id="gauge7" class="gauge-container seven">
  <span class="label">.seven</span>
</div>

<div class="info">
  Grab yours at <a class="link" href="https://github.com/naikus/svg-gauge" target="_blank">https://github.com/naikus/svg-gauge</a> Fork and star :D OR <pre>npm install svg-gauge</pre>
</div>

<div class="info">
  New feature! Change dial colors for different values. 
  
  <p class="warn">
  WARNING!! Some breaking changes: Gauge now uses a viewbox of 100x100 instead of previous 1000x1000. So all style stroke and font values need to be adjusted. (divide by 10)
  </p>
 
  
  <p>
    Also check out my tiny mobile view manager library for building simple SPAs
    <a target="_blank" href="https://codepen.io/naikus/pen/PKgPyN" class="link">
      https://codepen.io/naikus/pen/PKgPyN
    </a>
    and 
    
    <a target="_blank" class="link" href="https://codepen.io/naikus/project/full/AzkkER">the project here</a>
  </p>
</div>

              
            
!

CSS

              
                body {
  background-color: rgba(0,0,0,0.8);
  color: #999;
  font-family: Hevletica, sans-serif;
}

.info {
  clear: both;
  padding: 10px;
  font-size: 0.9em;
}
a.link {
  color: rgb(47, 227, 255);
  text-decoration: none;
}

.warn {
  font-size: 0.8em;
  background-color: darken(orange, 15%);
  color: #fff;
  padding: 10px;
}

/* ------ Default Style ---------- */
.gauge-container {
  width: 150px;
  height: 150px;
  display: block;
  float: left;
  padding: 10px;
  background-color: #222;
  margin: 7px;
  border-radius: 3px;
  position: relative;
}
.gauge-container > .label {
  position: absolute;
  right: 0;
  top: 0;
  display: inline-block;
  background: rgba(0,0,0,0.5);
  font-family: monospace;
  font-size: 0.8em;
  padding: 5px 10px;
}
.gauge-container > .gauge .dial {
  stroke: #334455;
  stroke-width: 2;
  fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value {
  stroke: rgb(47, 227, 255);
  stroke-width: 2;
  fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value-text {
  fill: rgb(47, 227, 255);
  font-family: sans-serif;
  font-weight: bold;
  font-size: 0.8em;
}




/* ------- Alternate Style ------- */
.wrapper {
  height: 100px;
  float: left;
  margin: 7px;
  overflow: hidden;
}
.wrapper > .gauge-container {
  margin: 0;
}
.gauge-container.two {
}
.gauge-container.two > .gauge .dial {
  stroke: #334455;
  stroke-width: 10;
}
.gauge-container.two > .gauge .value {
  stroke: orange;
  stroke-dasharray: none;
  stroke-width: 13;
}
.gauge-container.two > .gauge .value-text {
  fill: #ccc;
  font-weight: 100;
  font-size: 1em;
}



/* ------- Alternate Style ------- */
.gauge-container.three {
}
.gauge-container.three > .gauge .dial {
  stroke: #334455;
  stroke-width: 2;
}
.gauge-container.three > .gauge .value {
  stroke: #C9DE3C;
  stroke-width: 5;
}
.gauge-container.three > .gauge .value-text {
  fill: #C9DE3C;
} 



/* ----- Alternate Style ----- */
.gauge-container.four > .gauge .dial {
  stroke: #334455;
  stroke-width: 10;
}
.gauge-container.four > .gauge .value {
  stroke: #F32450;
  stroke-dasharray: none;
  stroke-width: 10;
}
.gauge-container.four > .gauge .value-text {
  fill: #F32450;
  transform: translate3d(26%, 20%, 0);
  display: inline-block;
}
.gauge-container.four .value-text {
  color: #F32450;
  font-weight: 100;
  position: absolute;
  bottom: 18%;
  right: 10%;
  display: inline-block;
} 



/* ----- Alternate Style ----- */
.gauge-container.five > .gauge .dial {
  stroke: #334455;
  stroke-width: 5;
}
.gauge-container.five > .gauge .value {
  stroke: #F8774B;
  stroke-dasharray: 25 1;
  stroke-width: 5;
}
.gauge-container.five > .gauge .value-text {
  fill: #F8774B;
  font-size: 0.7em;
}



/* ----- Alternate Style ----- */
  .gauge-container.six > .gauge .dial {
    stroke: #334455;
    fill: "#334455";
    stroke-width: 20;
  }
  .gauge-container.six > .gauge .value {
    stroke: #FF6DAF;
    stroke-width: 20;
  }
  .gauge-container.six > .gauge .value-text {
    fill: #FF6DAF;
    font-size: 0.7em;
  }


.gauge-container.seven > .gauge .dial {
  stroke: transparent;
  stroke-width: 5;
  transform: scale(0.9,0.9) translate3d(5.5px, 5.5px, 0);
  fill: rgba(148, 112, 57, 0.42);
}
.gauge-container.seven > .gauge .value {
  stroke: #F8774B;
  stroke-dasharray: none;
  stroke-width: 5;
}
              
            
!

JS

              
                var gauge1 = Gauge(
  document.getElementById("gauge1"), {
    max: 100,
    dialStartAngle: -90,
    dialEndAngle: -90.001,
    value: 100,
    label: function(value) {
      return Math.round(value * 100) / 100;
    }
  }
);

var gauge2 = Gauge(
  document.getElementById("gauge2"), {
    min: -50,
    max: 50,
    dialStartAngle: 180,
    dialEndAngle: 0,
    value: 50,
     color: function(value) {
        if(value < -25) {
          return "#5ee432";
        }else if(value < 0) {
          return "#fffa50";
        }else if(value < 25) {
          return "#f7aa38";
        }else {
          return "#ef4655";
        }
      }
  }
);

var gauge3 = Gauge(
  document.getElementById("gauge3"), {
    max: 100,
    value: 50
  }
);

var gauge4 = Gauge(
  document.getElementById("gauge4"), {
    max: 30000,
    dialStartAngle: 90,
    dialEndAngle: 0,
    value: 50
  }
);

var gauge5 = Gauge(
  document.getElementById("gauge5"), {
    max: 200,
    dialStartAngle: 0,
    dialEndAngle: -180,
    value: 50
  }
);

var gauge6 = Gauge(
  document.getElementById("gauge6"), {
    max: 100,
    dialStartAngle: 90.01,
    dialEndAngle: 89.99,
    dialRadius: 10,
    showValue: false,
    value: 50
  }
);


var gauge7 = Gauge(
  document.getElementById("gauge7"), {
    max: 100,
    dialStartAngle: -90,
    dialEndAngle: -90.001,
    value: 100,
    showValue: false,
    label: function(value) {
      return Math.round(value * 100) / 100;
    }
  }
);




(function loop() {
  var value1 = Math.random() * 100,
      value2 = Math.random() * 100,
      value3 = Math.random() * 100,
      value4 = Math.random() * 100,
      value5 = Math.random() * 100;

  // setValueAnimated(value, durationInSecs);
  // var maxVals = [100, 200];
  // gauge1.setMaxValue(maxVals[Math.round(Math.random())])
  gauge1.setValueAnimated(value1, 1);
  gauge2.setValueAnimated(50 - value2, 2);
  gauge3.setValueAnimated(value3, 1.5);
  gauge4.setValueAnimated(value4 * 300, 2);
  gauge5.setValueAnimated(value5 * 2, 1);
  gauge6.setValueAnimated(value1, 1);
  gauge7.setValueAnimated(value1, 1);
  window.setTimeout(loop, 4000);
})();
              
            
!
999px

Console