Skip to content

Commit 41caa7b

Browse files
committed
Added math logic.
Co-authored-by: Natalie Umanzor nmczormick
1 parent c4d65e3 commit 41caa7b

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

app/charts/memory-chart.jsx

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
import React, { useContext } from 'react';
2-
// You can change the chart property imported to the one that suits your needs.
32
import { Bar } from 'react-chartjs-2';
43
import HealthContext from '../context/DetailsContext';
54

65
const MemoryChart = () => {
7-
// ! Do not change the variables related to context.
86
const healthData = useContext(HealthContext);
9-
const health = healthData.detailsData;
7+
// const health = healthData.detailData;
108

11-
// Helper function
129
const createChart = () => {
13-
// Object for storing data
1410
const memoryObj = {
1511
free: 0,
1612
active: 0,
1713
used: 0,
18-
total: 0
14+
total: 0,
1915
};
2016

21-
// Iterate through HealthInfo to creat an object with data needed to create your graph.
22-
for (let i = 0; i < health.length; i += 1) {
23-
//Mongo
24-
if (health[i].freeMemory) {
25-
memoryObj.free += health[i].freeMemory
26-
memoryObj.active += health[i].activeMemory
27-
memoryObj.used += health[i].usedMemory
28-
memoryObj.total += health[i].totalMemory
29-
} else if (health[i].freememory) {
30-
memoryObj.free += health[i].freememory;
31-
memoryObj.active += health[i].activememory;
32-
memoryObj.used += health[i].usedmemory;
33-
memoryObj.total += health[i].totalmemory;
17+
for (let i = 0; i < healthData.length; i += 1) {
18+
console.log(healthData);
19+
// If Mongo
20+
if (healthData[i].freeMemory) {
21+
memoryObj.free += healthData[i].freeMemory;
22+
memoryObj.active += healthData[i].activeMemory;
23+
memoryObj.used += healthData[i].usedMemory;
24+
memoryObj.total += healthData[i].totalMemory;
25+
} else if (healthData[i].freememory) {
26+
memoryObj.free += healthData[i].freememory;
27+
memoryObj.active += healthData[i].activememory;
28+
memoryObj.used += healthData[i].usedmemory;
29+
memoryObj.total += healthData[i].totalmemory;
3430
}
3531
}
36-
memoryObj.free /= 1000000000
37-
memoryObj.active /= 1000000000
38-
memoryObj.used /= 1000000000
39-
memoryObj.total /= 100000000
4032

41-
// ! Chart Data
42-
// * --- Change the object used in data to the one you created.
43-
// * --- Labels must be in the same order as the keys in your object.
33+
memoryObj.free /= 1000000000 * healthData.length;
34+
memoryObj.active /= 1000000000 * healthData.length;
35+
memoryObj.used /= 1000000000 * healthData.length;
36+
memoryObj.total /= 1000000000 * healthData.length;
37+
4438
const chartData = {
4539
datasets: [
4640
{
@@ -66,4 +60,4 @@ const MemoryChart = () => {
6660
return <div>{createChart()}</div>;
6761
};
6862

69-
export default MemoryChart;
63+
export default MemoryChart;

0 commit comments

Comments
 (0)