Demo - Gauge Ticks with Text
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://test-9c0be.firebaseapp.com/wijmo/styles/wijmo.css">
<script src="https://test-9c0be.firebaseapp.com/wijmo/controls/wijmo.js"></script>
<script src="https://test-9c0be.firebaseapp.com/wijmo/controls/wijmo.input.js"></script>
<script src="https://test-9c0be.firebaseapp.com/wijmo/controls/wijmo.gauge.js"></script>
<div class="container">
<h1>
Gauge Ticks with Text
</h1>
<div class="row">
<div class="col-xs-6">
<div id="theRadialGauge"></div>
</div>
<div class="col-xs-6">
<label>
startAngle
<input id="start">
</label>
<label>
sweepAngle
<input id="sweep">
</label>
<label>
tickSpacing
<input id="spacing">
</label>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div id="theLinearGauge"></div>
</div>
<div class="col-xs-6">
<label>
direction
<input id="direction">
</label>
</div>
</div>
</div>
CSS
label {
display: block;
text-align: right;
width: 300px;
}
label .wj-combobox {
width: 120px;
}
.wj-gauge {
margin: 4em auto;
}
.wj-radialgauge {
width: 200px;
}
.wj-radialgauge .tick-text text {
font-size: 50%;
text-anchor: middle;
dominant-baseline: middle; /* center-aligns CSS text vertically! */
}
.wj-lineargauge {
width: 400px;
}
.wj-lineargauge.vertical {
height: 300px;
width: 2em;
}
.wj-lineargauge .tick-text text {
font-size: 75%;
text-anchor: middle;
dominant-baseline: middle; /* center-aligns CSS text vertically! */
}
body {
font-size: 16px;
margin-bottom: 48pt;
}
JavaScript
onload = function() {
// create gauges
var theRadialGauge = new wijmo.gauge.RadialGauge('#theRadialGauge', {
min: 0,
max: 500,
value: 100,
startAngle: -45,
sweepAngle: -270,
showTicks: true,
tickSpacing: 50,
showText: 'Value',
isReadOnly: false,
refreshed: updateTicks
});
var theLinearGauge = new wijmo.gauge.LinearGauge('#theLinearGauge', {
min: 0,
max: 500,
value: 100,
showTicks: true,
tickSpacing: 50,
isReadOnly: false,
refreshed: updateTicks
});
// configure gauges
new wijmo.input.ComboBox('#start', {
itemsSource: [-90, -45, 0, 45, 90],
selectedItem: -45,
selectedIndexChanged: function(s, e) {
theRadialGauge.startAngle = s.selectedItem;
}
});
new wijmo.input.ComboBox('#sweep', {
itemsSource: [-360, -270, -180, -90, 90, 180, 270, 360],
selectedItem: -270,
selectedIndexChanged: function(s, e) {
theRadialGauge.sweepAngle = s.selectedItem;
}
});
new wijmo.input.ComboBox('#spacing', {
itemsSource: [20, 50, 100, 200, 250],
selectedItem: 100,
selectedIndexChanged: function(s, e) {
theRadialGauge.tickSpacing = s.selectedItem;
theLinearGauge.tickSpacing = s.selectedItem;
}
});
new wijmo.input.ComboBox('#direction', {
itemsSource: 'Left,Right,Up,Down'.split(','),
selectedItem: 'Right',
selectedIndexChanged: function(s, e) {
theLinearGauge.direction = s.selectedItem;
wijmo.toggleClass(theLinearGauge.hostElement, 'vertical', s.text.match(/Up|Down/) != null);
}
});
// add text to tickmarks
function updateTicks(s) {
// get tickText element
var tickText = s.hostElement.querySelector('.tick-text');
if (!tickText) {
var svg = s.hostElement.querySelector('svg');
tickText = document.createElementNS('http://www.w3.org/2000/svg', 'g');
wijmo.addClass(tickText, 'tick-text');
svg.appendChild(tickText);
}
// clear tickText element
...