customize the chart legent texts

This commit is contained in:
saravanan30erd 2019-10-25 19:48:24 +04:00
parent 097ea5b351
commit 10450f218a
2 changed files with 16 additions and 13 deletions

View file

@ -25,8 +25,8 @@ output = []
# Functions # Functions
def calculate_percentage(data): def calculate_count(data):
perc = {} count = {}
ls = data.values() ls = data.values()
z, nz = 0,0 z, nz = 0,0
for v in ls: for v in ls:
@ -34,9 +34,9 @@ def calculate_percentage(data):
z += 1 z += 1
else: else:
nz += 1 nz += 1
perc['green'] = (float(z)*100)/len(ls) count['green'] = z
perc['red'] = (float(nz)*100)/len(ls) count['red'] = nz
return perc return count
def getMonit(): def getMonit():
@ -65,9 +65,8 @@ def getMonit():
sorted_checks = OrderedDict() sorted_checks = OrderedDict()
sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True)) sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True))
perc = calculate_percentage(sorted_checks) count = calculate_count(sorted_checks)
print perc server = dict(name=site, url=s['url'], result=sorted_checks, s_rate=count)
server = dict(name=site, url=s['url'], result=sorted_checks, s_rate=perc)
output.append(server) output.append(server)

View file

@ -9,8 +9,11 @@ for (i = 0; i < acc.length; i++) {
} }
function draw(rate) { function draw(rate) {
console.log(rate) var count = [rate['green'], rate['red']];
var percentage = [rate['green'], rate['red']]; var percentage = [
(count[0]*100)/(count[0]+count[1]),
(count[1]*100)/(count[0]+count[1])
]
var status = ['Ok', 'Error']; var status = ['Ok', 'Error'];
var green = (percentage[0]*2)/100; var green = (percentage[0]*2)/100;
var red = (percentage[1]*2)/100; var red = (percentage[1]*2)/100;
@ -41,12 +44,13 @@ function draw(rate) {
ctx.stroke(); ctx.stroke();
ctx.fill(); ctx.fill();
ctx.rect(canvas.width - 105, i * 20 + 10, 10, 10); ctx.rect(canvas.width - 129, i * 20 + 10, 10, 10);
ctx.fill(); ctx.fill();
ctx.font = "13px sans-serif"; ctx.font = "13px sans-serif";
//ctx.font = "20px Georgia"; //ctx.font = "20px Georgia";
ctx.fillText(status[i] + " - " + Number(percentage[i]).toFixed(1) + " %", ctx.fillText(status[i] + " - " + count[i] + " (" +
canvas.width - 85, i * 20 + 20); Number(percentage[i]).toFixed(1) + "%)",
canvas.width - 109, i * 20 + 20);
} }
} }
} }