-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderHelper.js
More file actions
executable file
·96 lines (90 loc) · 2.55 KB
/
Copy pathRenderHelper.js
File metadata and controls
executable file
·96 lines (90 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var bgColorList= [
'rgba(255, 99, 132, 0.9)',
'rgba(54, 162, 235, 0.9)',
'rgba(255, 206, 86, 0.9)',
'rgba(75, 192, 192, 0.9)',
'rgba(153, 102, 255, 0.9)',
'rgba(255, 159, 64, 0.9)'
]
var borderColor= [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
]
function addData(chart, label, data) {
console.log(label, data)
chart.data.labels.push(label);
chart.data.datasets.forEach((dataset) => {
dataset.data.push(data);
bgcolor = bgColorList[Math.floor(Math.random() * bgColorList.length)];
dataset.backgroundColor.push(bgcolor);
});
chart.update();
}
function removeData(chart) {
chart.data.labels.pop();
chart.data.datasets.forEach((dataset) => {
dataset.data.pop();
});
chart.update();
}
function initChart(targetChart,chartType,chartTitle,CommData) {
var myChart = new Chart(targetChart, {
type: chartType,
data: {
labels: [],
datasets: [{
label: '',
data: [],
backgroundColor: [],
}]
},
options: {
title: {
display: true,
text: chartTitle,
fontSize: 18
},
scales: {
xAxes: [{
gridLines: {
display: true,
},
}],
yAxes: [{
display: false,
gridLines: {
display: false,
},
ticks: {
display: false,
beginAtZero: true
}
}]
}
}
});
loadChartData(myChart, CommData)
console.log(myChart.data)
}
function loadChartData(chart, Commdata) {
console.log(typeof chart)
$.ajax({
type: "POST",
url: switchAggregateUrl(CommData.queryTypeId),
data: CommData,
success: function (data) {
$.each(data, function (index, rec) {
//console.log(rec.name, rec.count)
addData(chart, rec.name, rec.count)
})
},
error: function (xhr, type, exception) {
// if ajax fails display error alert
alert("ajax error response type " + type)
}
})
}