This commit is contained in:
zakhy 2024-12-09 12:32:29 +07:00
parent 0031d1b05f
commit 38bb67000d
2 changed files with 130 additions and 0 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
[Документация по спидометру ](https://jscharting.com/examples/chart-types/circular-gauge/)
Пример находится в [файле gauge.html](code/gauge.html)
Поля ввода находятся в [файле index.html](code/index.html)

126
code/gauge.html Normal file
View File

@ -0,0 +1,126 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="chartDiv" style="max-width: 400px; height: 280px;margin: 0px auto;"></div>
<script src="https://code.jscharting.com/latest/jscharting.js"></script>
<script type="text/javascript">
/*
Gauge using a colorized axis line with breaks and a data point on top of the axis line.
Learn how to:
- Draw a circular gauge chart.
*/
// JS
var INTERVAL_ID,
animationDuration = 420,
updateInterval = 1500;
var chart = JSC.chart(
'chartDiv',
{
debug: false,
type: 'gauge ',
legend_visible: false,
animation_duration: animationDuration,
xAxis: {
scale: {
// Helps position the marker on top of the y Axis.
range: [0, 1]
}
},
palette: {
pointValue: '%yValue',
ranges: [
{value: [0, 30], color: '#FF5353'},
{value: [30, 50], color: '#FFD221'},
{value: [50, 70], color: '#fcb772'},
{value: [70, 100], color: '#77E6B4'}
]
},
yAxis: {
defaultTick: {
// Pads around the gauge
padding: 13,
label_visible: false
},
line: {
width: 15,
// Gaps occur at tick intervals defined below.
breaks_gap: 0.03,
color: 'smartPalette'
},
scale: {range: [0, 100], interval: 10}
},
defaultSeries: {
opacity: 1,
mouseTracking_enabled: false,
shape: {
label: [
{
text: '%value%',
style: {fontSize: 48},
align: 'center',
verticalAlign: 'middle'
},
{
text: labelText(50),
style: {fontSize: 48},
align: 'center',
verticalAlign: 'middle'
}
]
}
},
series: [
{
type: 'marker',
defaultPoint: {
marker: {
outline: {width: 10, color: 'currentColor'},
fill: 'white',
type: 'circle',
size: 30
}
},
points: [{y: 50}]
}
],
},
);
/**
* Updates the chart with a random value.
* @param chrt
*/
function updateChart(chrt) {
chrt = chart || chrt;
var series = chrt.series(0),
rValue = Math.round(Math.random() * 100);
series.options({shape_label: [{}, {text: labelText(rValue)}]}, {animation: false});
series.points(0).options({y: rValue});
}
function playPause(val) {
if (val) {
clearInterval(INTERVAL_ID);
} else {
INTERVAL_ID = setInterval(function () {
updateChart(chart);
}, updateInterval);
}
}
function labelText(value) {
var fgg = value >= 70 ? 'Great!' : value >= 30 ? 'Good' : 'Fair';
return '<span style="fontSize: 32px">' + fgg + '</span>';
}
</script>
</body>
</html>