Skip to content

Commit ebaafcb

Browse files
author
hoang.tran12
committed
stacked bar chart
1 parent 12a6a04 commit ebaafcb

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/_ufs_statistic.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,56 @@ export default {
117117
});
118118

119119
// ======================== Per script name Per hour ========================
120+
// Stacked Bar Chart for each script
121+
const scriptNamePerHour_dataset = Array.from(
122+
scriptNameCount.keys()
123+
).map((scriptName) => {
124+
const data = Array(24).fill(0);
125+
logData.forEach((log) => {
126+
let lastColon = log.lastIndexOf(":");
127+
let lastArrow = log.lastIndexOf("->");
128+
let scriptName_log = log.substring(lastColon + 1, lastArrow - 1);
129+
if (scriptName_log === scriptName) {
130+
let hour = extractTime(log).getHours();
131+
data[hour]++;
132+
}
133+
});
134+
return {
135+
label: scriptName,
136+
data,
137+
backgroundColor: `rgb(${Math.floor(
138+
Math.random() * 255
139+
)},${Math.floor(Math.random() * 255)},${Math.floor(
140+
Math.random() * 255
141+
)})`,
142+
};
143+
});
144+
145+
const canvas3 = document.createElement("canvas");
146+
canvas3.style.cssText = "max-width: 900px; max-height: 300px;";
147+
document.body.prepend(canvas3);
148+
const ctx3 = canvas3.getContext("2d");
149+
const scriptNamePerHourChart = new Chart(ctx3, {
150+
type: "bar",
151+
data: {
152+
labels: Array.from({ length: 24 }, (_, i) => `${i}:00`),
153+
datasets: scriptNamePerHour_dataset,
154+
},
155+
options: {
156+
interaction: {
157+
intersect: false,
158+
},
159+
responsive: true,
160+
scales: {
161+
x: {
162+
stacked: true,
163+
},
164+
y: {
165+
stacked: true,
166+
},
167+
},
168+
},
169+
});
120170
}
121171
);
122172
})();

0 commit comments

Comments
 (0)