Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K #23

Closed
wants to merge 2 commits into from
Closed

K #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
180 changes: 180 additions & 0 deletions FRONTEND/chart.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Line Chart Example</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
}

.chart-container {
width: 100%;
max-width: 800px;
margin: auto;
padding: 20px;
}

canvas {
width: 100%;
height: 400px;
}

.controls {
display: flex;
justify-content: space-around;
width: 100%;
max-width: 800px;
margin: 20px 0;
}

select,
button {
padding: 10px;
font-size: 16px;
}
</style>
</head>

<body>
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>

<div class="controls">
<select id="interval">
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="yearly">Yearly</option>
</select>
<button id="resetZoom">Reset Zoom</button>
</div>

<script>
async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
return data;
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
return [];
}
}

function createChart(data, interval) {
const ctx = document.getElementById('myChart').getContext('2d');

const chart = new Chart(ctx, {
type: 'line',
data: {
labels: data.map(item => item.date),
datasets: [
{
label: 'Close Amount',
data: data.map(item => item.close_amount),
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 2,
fill: true,
pointStyle: false,
},
{
label: 'Holding Amount',
data: data.map(item => item.holding_amount),
borderColor: 'rgba(153, 102, 255, 1)',
borderWidth: 2,
fill: true,
pointStyle: false,
}
]
},
options: {
responsive: true,
scales: {
x: {
type: 'category',
title: {
display: true,
text: 'Date'
}
},
y: {
title: {
display: true,
text: 'Amount'
}
}
},
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Comparison of Close and Holding Amounts'
},
zoom: {
pan: {
enabled: true,
mode: 'x',
},
zoom: {
wheel: {
enabled: true,
},
pinch: {
enabled: true
},
mode: 'x',
}
}
}
}
});

document.getElementById('resetZoom').addEventListener('click', () => {
chart.resetZoom();
});

return chart;
}



// URL to the JSON data
const dataUrl = '../DATA/GOLD/Holdings/Holdings_data_v3.json';

// Fetch data and create chart
fetchData(dataUrl).then(data => {
// Update each item's date to a Date object
data = data.map(item => {
item.date = new Date(item.date).toISOString().split('T')[0]; // Convert the date string to a Date object
return item; // Return the modified item
});

let chart = createChart(data, "daily");

document.getElementById('interval').addEventListener('change', (event) => {
const interval = event.target.value;
chart.destroy();
chart = createChart(data, interval);
});
});

</script>
</body>

</html>
170 changes: 0 additions & 170 deletions FRONTEND/charts-chartjs.html

This file was deleted.

7 changes: 0 additions & 7 deletions FRONTEND/css/app.css

This file was deleted.

1 change: 0 additions & 1 deletion FRONTEND/css/app.css.map

This file was deleted.

Empty file removed FRONTEND/fonts/.gitkeep
Empty file.
Loading
Loading