I using ZingChart to do gauge chart. The chart only display first and last section only. Two section missing in between. I have 5 values, but I want to display for 4 value only. So, I created 4 rules for ring(arr_ringrules
) and plot(arr_plotrules
) and pass the rules arrays to object. But, only first and last section display in colour defined in rules.
$(document).ready(function() {
window.feed = function(callback) {
var tick = {};
tick.plot0 = Math.ceil(350 + (Math.random() * 500));
callback(JSON.stringify(tick));
};
d = [150, 200, 250, 300, 400];
let sum = d.reduce(function(a, b) {
return a + b;
}, 0);
perc_array = [];
perc_rulescolor = []
colour_array = ["#11d8ee", "#3cc457", "#f12b0e", "#dda522"];
perc = '';
for (i = 0; i < d.length; i++) {
perc = parseInt((d[i] / sum) * 100);
perc_array.push(perc);
if (typeof colour_array[i] === 'undefined') {
} else {
if (i == 0) {
obj_color = {
rule: "%v < " + perc + " && %v >= 0",
'backgroundColor': colour_array[i]
};
} else {
prev_array_val = perc_array[(i - 1)];
console.log(prev_array_val + '=>' + perc);
obj_color = {
rule: "%v < " + perc + " && %v >= " + prev_array_val,
'backgroundColor': colour_array[i]
}
}
perc_rulescolor.push(obj_color);
}
}
arr_ringrules = [{
rule: '%v >= 0 && %v < 11.54',
backgroundColor: '#0cf311'
},
{
rule: '%v >= 11.54 && %v < 15.38',
backgroundColor: '#eaf50a'
},
{
rule: '%v >= 15.38 && %v < 19.23',
backgroundColor: '#db7b24'
},
{
rule: '%v >= 19.23 && %v < 23.08',
backgroundColor: '#ff0000'
}
];
arr_plotrules = [{
rule: '%v >= 0 && %v < 11.54',
text: '%v<br>EXCELLENT'
},
{
rule: '%v >= 11.54 && %v < 15.38',
text: '%v<br>Good'
},
{
rule: '%v >= 15.38 && %v < 19.23',
text: '%v<br>Fair'
},
{
rule: '%v >= 19.23 && %v < 23.08',
text: '%v<br>Bad'
}
];
var myConfig = {
type: "gauge",
globals: {
fontSize: 25
},
plotarea: {
marginTop: 80
},
plot: {
size: '100%',
valueBox: {
placement: 'center',
text: '%v', //default
fontSize: 35,
rules: arr_plotrules
}
},
tooltip: {
borderRadius: 5
},
scaleR: {
aperture: 180,
values: "0:100:20",
center: {
visible: false
},
tick: {
visible: false
},
item: {
offsetR: 0,
rules: [{
rule: '%i == 9',
offsetX: 15
}]
},
labels: ['0', '20', '40', '60', '80', '100'],
ring: {
size: 100,
rules: arr_ringrules
}
},
series: [{
values: [80], // starting value
backgroundColor: 'black',
indicator: [10, 10, 10, 10, 0.75],
animation: {
effect: 2,
method: 1,
sequence: 4,
speed: 900
},
}]
};
zingchart.render({
id: 'myChart',
data: myConfig,
height: 500,
width: '100%'
});
})
html,
body {
height: 100%;
width: 100%;
}
#myChart {
height: 100%;
width: 100%;
min-height: 150px;
}
.zc-ref {
display: none;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingSoft Demo</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<div id='myChart'><a class="zc-ref" href="https://www.zingchart.com/">Charts by ZingChart</a></div>
</body>
</html>