Skip to content

Commit 6354c7e

Browse files
authored
Merge pull request #1427 from plotly/gauge
gauge charts
2 parents 95e4a01 + cc75ffe commit 6354c7e

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: JavaScript Graphing Library D3.js-based Gauge Charts| Examples | Plotly
3+
name: Gauge Charts
4+
permalink: javascript/gauge-charts/
5+
description: How to make a D3.js-based gauge chart in javascript.
6+
layout: user-guide
7+
thumbnail: thumbnail/gauge.jpg
8+
language: plotly_js
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as: financial
12+
order: 4
13+
redirect_from: javascript-graphing-library/gauge-charts
14+
---
15+
{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","gauge-charts" | sort: "order" %}
16+
{% include auto_examples.html examples=examples %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Add Steps, Threshold, and Delta
3+
plot_url: https://codepen.io/plotly/embed/zgwrMW/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: gauge-charts
6+
order: 2
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
The following examples include "steps" attribute shown as shading inside the radial arc, "delta" which is the
12+
difference of the value and goal (reference - value), and "threshold" to determine boundaries that visually alert you if the value cross a defined threshold.
13+
---
14+
var data = [{domain: {x: [0, 1], y: [0, 1]}, value: 450, title: {text: "Speed"},
15+
type: "indicator", mode: "gauge+number+delta", delta: {reference: 380}, gauge:
16+
{axis: {range: [null, 500]}, steps: [{range: [0, 250], color: "lightgray"},
17+
{range: [250, 400], color: "gray"}], threshold: {line: {color: "red", width: 4},
18+
thickness: 0.75, value: 490}}}];
19+
20+
var layout = {width: 600, height: 500, margin: {t: 0, b: 0}};
21+
Plotly.newPlot(gd,data,layout);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Basic Gauge
3+
plot_url: https://codepen.io/plotly/embed/aeWOEx/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: gauge-charts
6+
order: 1
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
A radial gauge chart has a circular arc, which displays a single value to estimate progress toward a goal.
12+
The bar shows the target value, and the shading represents the progress toward that goal. Gauge charts, known as
13+
speedometer charts as well. This chart type is usually used to illustrate key business indicators.
14+
15+
The example below displays a basic gauge chart with default attributes. For more information about different added attributes check [indicator](https://plot.ly/javascript/indicator/) tutorial.
16+
---
17+
var data = [{domain: {x: [0, 1], y: [0, 1]}, value: 270, title: {text: "Speed"},
18+
type: "indicator", mode: "gauge+number"}];
19+
20+
var layout = {width: 500, height: 500, margin: {t: 0, b: 0}};
21+
Plotly.newPlot(gd,data,layout);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Custom Gauge Chart
3+
plot_url: https://codepen.io/plotly/embed/zgZYmZ/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: gauge-charts
6+
order: 3
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
The following example shows how to style your gauge charts. For more information about all possible options check our [reference page](https://plot.ly/javascript/reference/#indicator).
12+
---
13+
var data = [{domain: {x: [0, 1], y: [0, 1]}, value: 420, title: {text: "Speed",
14+
font: {size: 24}}, type: "indicator", mode: "gauge+number+delta",
15+
delta: {reference: 400, increasing: {color: "RebeccaPurple"}},
16+
gauge: {axis: {range: [null, 500], tickwidth: 1, tickcolor: "darkblue"},
17+
bar: {color: "darkblue"}, bgcolor: "white", borderwidth: 2, bordercolor: "gray",
18+
steps: [{range: [0, 250], color: 'cyan'}, {range: [250, 400], color: 'royalblue'
19+
}], threshold: {line: {color: "red", width: 4}, thickness: 0.75, value: 490}}}];
20+
21+
var layout = {width: 500, height: 400, margin: {t: 25, r: 25, l: 25, b: 25},
22+
paper_bgcolor: "lavender", font: {color: "darkblue", family: "Arial"}};
23+
24+
Plotly.newPlot(gd,data,layout);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Multi Gauge
3+
plot_url: https://codepen.io/plotly/embed/bXBVZp/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: gauge-charts
6+
order: 4
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
11+
Gauge charts are useful for comparing values between a small number of variables by using multiple gauges.
12+
13+
---
14+
var data = [
15+
{
16+
domain: {x: [0, 0.5], y: [0.5, 1]}, value: 350, title: {text: "Speed"},
17+
type: "indicator", mode: "gauge+number", delta: {reference: 400}, gauge: {axis:
18+
{range: [null, 500]}, bar:{color:"darkblue"}, steps: [{range: [0, 250],
19+
color: "cyan"}, {range: [250, 400], color: "royalblue"}], threshold: {line:
20+
{color: "red", width: 4}, thickness: 0.8, value: 490}}},
21+
{
22+
domain: {x: [0.6, 1], y: [0.5, 0.8]}, value: 300, type: "indicator",
23+
title: {text: "Speed<br><span style='font-size:0.8em;color:gray'>Time</span>"},
24+
delta: {reference: 400}, gauge: {axis: {range: [null, 500]},
25+
bar:{color:"darkblue"}, bgcolor: "white", steps: [{range: [0, 250],
26+
color: "cyan"}, {range: [250, 400], color: "royalblue"}], mode: "gauge+delta",
27+
threshold: {line: {color: "red", width: 4}, thickness: 0.75, value: 490}}},
28+
{
29+
domain: {x: [0, 1], y: [0, 0.4]}, value: 240, title: {"text": "Speed"},
30+
type: "indicator", mode: "gauge+number+delta", delta: {"reference": 400},
31+
gauge: {bar: {color: "darkblue"}, axis: {range: [null, 500]}, steps: [{range: [0, 250],
32+
color: "cyan"}, {range: [250, 400], color: "royalblue"}],
33+
threshold: {line: {color: "red", width: 4}, thickness: 0.75, value: 490}}}];
34+
35+
var layout = {width: 500, height: 500, margin: {t: 25, r: 25, l: 25, b: 25},
36+
shapes: [{type: "rect", x0: -0.03, x1: 0.56, y0: 0.55, y1: 1,
37+
line: {color: "gray", width: 1}}]};
38+
39+
Plotly.newPlot(gd,data,layout);

0 commit comments

Comments
 (0)