Skip to content

Commit

Permalink
Added Data Visualization Calculator (#1978)
Browse files Browse the repository at this point in the history
  • Loading branch information
R2-STAR authored Jan 8, 2025
1 parent a66ed83 commit 89e57c7
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Calculators/Data-Visualization-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# <p align="center">Data Visualization Calculator</p>

## Description :-

This is a simple web-based calculator that allows users to input numerical data and visualize it using bar charts.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

1. User Input: Accepts numerical input from the user.
2. Bar Chart Visualization: Displays a bar for each input number.
3. Clear Functionality: Resets the chart.

## Screenshots :-

![image](https://github.com/user-attachments/assets/e0865b50-ff02-4d49-b90d-2cddc10407cb)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Calculators/Data-Visualization-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="style.css">
<title>Data Visualization Calculator</title>
</head>

<body>
<div class="container">
<h1>Data Visualization Calculator</h1>

<form id="data-form">
<div class="form-group">
<label for="labels">Enter Labels (comma-separated):</label>
<input type="text" id="labels" placeholder="e.g., January, February, March" required>
</div>

<div class="form-group">
<label for="values">Enter Values (comma-separated):</label>
<input type="text" id="values" placeholder="e.g., 10, 20, 30" required>
</div>

<button type="button" id="generate-chart">Generate Chart</button>
</form>

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

<script src="script.js"></script>
</body>

</html>
47 changes: 47 additions & 0 deletions Calculators/Data-Visualization-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
document.getElementById("generate-chart").addEventListener("click", function () {
const labelsInput = document.getElementById("labels").value;
const valuesInput = document.getElementById("values").value;

if (!labelsInput || !valuesInput) {
alert("Please fill in both labels and values!");
return;
}

const labels = labelsInput.split(",").map(label => label.trim());
const values = valuesInput.split(",").map(value => parseFloat(value.trim()));

if (labels.length !== values.length) {
alert("The number of labels must match the number of values!");
return;
}

// Create the chart
const ctx = document.getElementById("chart").getContext("2d");

// Destroy the previous chart instance if it exists
if (window.myChart) {
window.myChart.destroy();
}

window.myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Values',
data: values,
backgroundColor: 'rgba(54, 162, 235, 0.6)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
});
63 changes: 63 additions & 0 deletions Calculators/Data-Visualization-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
background-image: url('assets/background.jpg');
background-size: cover;
background-position: center;
}

.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
color: #333;
}

.form-group {
margin-bottom: 15px;
}

label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

input {
width: 100%;
padding: 8px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
width: 100%;
padding: 10px;
color: #fff;
background: #007bff;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background: #0056b3;
}

.chart-container {
margin-top: 20px;
padding: 15px;
background: #e9f7ef;
border: 1px solid #c3e6cb;
border-radius: 4px;
}
6 changes: 6 additions & 0 deletions calculators.json
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@
"link": "./Calculators/Data-Size-Calculator/index.html",
"source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Data-Size-Calculator"
},
{
"title": "Data Visualization Calculator",
"description": "Displays a bar chart for input data.",
"link": "./Calculators/Data-Visualization-Calculator/index.html",
"source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Data-Visualization-Calculator"
},
{
"title": "Date Time Calculator",
"description": "Calculates Date & Time of the specific period.",
Expand Down

0 comments on commit 89e57c7

Please sign in to comment.