Skip to content
Open
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
101 changes: 101 additions & 0 deletions chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

let Dates = [];
let exrate = [];
let randomHexCode = [];
let currEx = "";
const RandomHexCode = () => {
for (let i = 0; i < 31; i++) {
randomHexCode.push('#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'));
}
console.log("Hexcode", randomHexCode)
}
const APIMeth = (start, end,CurrExchange) => {
currEx = (CurrExchange)? CurrExchange : 'INR';
let Datefilter = [];
let urls = ['https://api.exchangeratesapi.io/latest' , 'https://api.exchangeratesapi.io/2010-01-12',' https://api.exchangeratesapi.io/latest?base=USD',' https://api.exchangeratesapi.io/latest?symbols=USD']
Promise.all(urls.map(u => fetch(u))).then(responses =>
Promise.all(responses.map(res => res.json()))
).then(data => {
RandomHexCode()
console.log('fetched data [1]...', data[0]);
if (start && end) {
randomHexCode.length = 0;
Dates.length = 0;
exrate.length = 0;
RandomHexCode()
Object.keys(data[0]).filter((date) => {
if (new Date(date) > new Date(start) && new Date(date) < new Date(end)) {
data.map((item) => {
let exchangerate = item[date][currEx] / 1
Datefilter.push({ "date": date,"EXCH_Rate" : exchangerate})
})
}
})
} else {
Object.keys(data[0]).filter((date) => {
if (new Date(date) > new Date("2019-01-31")) { }
else {
data.map((item) => {
let exchangerate = item[date][currEx] / 1
Datefilter.push({ "date": date,"EXH_Rate": exchangerate})
})
}
})
}
console.log('Datefilter', Datefilter)
Datefilter.map((item) => {
Dates.push(item.date)
exrate.push(item.EXH_Rate)
})
var chart = document.getElementById('myChart');
var myChart = new Chart(chart, {
type: 'line',
data: {
labels: Dates,
datasets: [{
label: "Rate of Exchange",
fill: false,
lineTension: 0,
data: exrate,
pointBorderColor: "lawngreen",
borderColor: '#000000',
borderWidth: 2,
showLine: true,
}]
},
});



}).catch((err) => {
console.log('Error :', err)
})
}

const url = 'https://api.exchangeratesapi.io/latest';

fetch(url)
.then(
function(response) {
if (response.status !== 150) {
console.warn('Error: ' +
response.status);
return;
}

response.json().then(function(data) {
console.log('Select',data.rates)
let option;
Object.keys(data.rates).map((item) =>{
option = document.createElement('option');
option.text = item;
option.value = item;
dropdown.add(option);
})
});
}
)
.catch(function(err) {
console.error('Error Found :', err);
});
33 changes: 33 additions & 0 deletions main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>

<head>
<title>
INR VS EUR
</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css" rel="stylesheet" type="text/css">
</head>

<body onload="APIMeth()">
<h1>INR vs EUR </h1>
<section class="charts">
<div class="container-fluid">
<div class="row">
<div class="ri-bar-chart-box-line" id="Og-Barchat">
<div class="chart-container mt-5">
<h1>Line Graph</h1>
<canvas id="myChart" width="400" height="120"></canvas>
</div>
</div>
</div>
</div>
</section>
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js">
</script>
<script src="./chart.js"></script>
</body>
</html>