HTMLcopy
1
<form name="sipForm">
2
<div class="sip-calculator">
3
<h3 id="heading" style="margin-bottom: 1.5em; text-align: center;">PPF Calculator</h3>
4
5
<div class="sip-calculator-amount">
6
<p style="margin-top: 1.8em;">
7
<label id="amountLabel"> Monthly Investment</label>
8
<input name="Amount" id="inputAmount" type="number" step="500" value="5000" min="500" max="100000"
9
oninput="showValAmount(this.value)" />
10
<span id="amount"></span> Rs.
11
</p>
12
<input class="amount-slider" name="realAmount" id="myAmount" type="range" step="500" min="500" max="100000"
13
value="5000" />
14
</div>
15
<div class="sip-calculator-year">
16
<p style="margin-top: 1.8em;">
17
Number of Years
18
<input name="Years" id="inputYears" type="number" value="10" min="1" max="30"
19
oninput="showValYears(this.value)" />
20
<span id="years"></span> Yr
21
</p>
22
<input class="year-slider" name="realYears" id="myYears" type="range" min="1" max="30" value="10">
23
</div>
24
<div class="sip-calculator-roi">
25
<p style="margin-top: 1.8em;">
26
Returns
27
<input name="Retunrs" id="inputRoi" type="number" value="15" min="5" max="22"
28
oninput="showValRoi(this.value)" />
29
<span id="roi"></span> %
30
</p>
31
<input class="roi-slider" name="realRoi" id="myRoi" type="range" min="5" max="22" value="15">
32
</div>
33
<p style="margin-top: 1em;font-size: 1.2em; background: #f1f2f3; border-radius: 7px; padding: 20px;">
34
<strong>Your Wealth:</strong>
35
<span id="yourWealth" style="font-size: 1.2em;margin-left: 8px;"></span>
36
</p>
37
<!-- <div style="margin-top: 15px;"><img class="groww-logo" src="groww-logo-ed.png" target="_parent" align="right"/></div> -->
38
</div>
39
</form>
40
<div id="container"></div>
CSScopy
x
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
8
:root {
9
--background-color: white;
10
--vigo-color: #5367FF;
11
--slider-color: #00D09C;
12
--input-number-color: #EBEBEB;
13
}
14
15
* {
16
box-sizing: border-box;
17
margin: 0;
18
padding: 0;
19
}
20
21
h1 {
22
text-align: center;
23
margin-left: 0.2em;
24
margin-right: 0.2em;
25
margin-bottom: 0.9em;
26
}
27
28
body {
29
display: flex;
30
justify-content: center;
31
align-items: center;
32
font-family: 'Roboto', sans-serif;
33
background-color: var(--background-color);
34
color: #222;
35
}
36
37
#amountLabel {
38
width: 210px;
39
;
40
}
41
42
.sip-calculator {
43
border: 5px solid white;
44
-moz-box-shadow: 0px 0px 5px hsl(15, 2%, 55%);
45
-webkit-box-shadow: 0px 0px 5px hsl(15, 2%, 55%);
46
box-shadow: 0px 0px 10px hsl(0, 0%, 73.9%);
47
padding: 3em;
48
margin: 1em;
49
width: 530px;
50
background-color: white;
51
}
52
53
.sip-calculator-amount,
54
.sip-calculator-year,
55
.sip-calculator-roi {
56
margin-bottom: 2.2em;
57
width: 100%;
58
}
59
60
.amount-slider,
61
.year-slider,
62
.roi-slider {
63
width: 100%;
64
height: 1px;
65
border-radius: 10px;
66
background: var(--slider-color);
67
outline: none;
68
69
}
70
71
input[type=range] {
72
-moz-appearance: none;
73
-webkit-appearance: none;
74
appearance: none;
75
cursor: pointer;
76
}
77
78
input[type=range]:focus {
79
outline: none;
80
}
81
82
input[type=range]::-ms-track {
83
width: 100%;
84
cursor: pointer;
85
}
86
87
input[type=range]::-webkit-slider-thumb {
88
-webkit-appearance: none;
89
border: 2.5px solid var(--vigo-color);
90
height: 20px;
91
width: 20px;
92
border-radius: 40px;
93
background: white;
94
cursor: pointer;
95
margin-top: 0px;
96
97
}
98
99
input[type=range]::-moz-range-thumb {
100
border: 2.5px solid var(--vigo-color);
101
height: 20px;
102
width: 20px;
103
border-radius: 40px;
104
background: white;
105
cursor: pointer;
106
}
107
108
input[type=range]::-ms-thumb {
109
border: 2.5px solid var(--vigo-color);
110
height: 20px;
111
width: 20px;
112
border-radius: 40px;
113
background: white;
114
cursor: pointer;
115
}
116
117
input[type=number] {
118
-moz-appearance: none;
119
-webkit-appearance: none;
120
cursor: pointer;
121
background: var(--input-number-color);
122
border-style: none;
123
height: 30px;
124
margin-left: 20px;
125
margin-right: 10px;
126
text-align: right;
127
padding-right: 5px;
128
font-family: 'Roboto', sans-serif;
129
font-size: 1.5em;
130
border-radius: 4px;
131
/* float: right; */
132
}
133
134
input[type=number]:focus {
135
outline: none;
136
border: 1px solid #3197EE;
137
138
}
139
140
/* For radio */
141
.radio {
142
margin: 0.5rem;
143
text-align: center;
144
}
145
146
.radio input[type="radio"] {
147
position: absolute;
148
opacity: 0;
149
}
150
151
.radio input[type="radio"]+.radio-label:before {
152
content: '';
153
background: #f4f4f4;
154
border-radius: 100%;
155
border: 1px solid #b4b4b4;
156
display: inline-block;
157
width: 1.4em;
158
height: 1.4em;
159
position: relative;
160
top: -0.2em;
161
margin-right: 1em;
162
vertical-align: top;
163
cursor: pointer;
164
text-align: center;
165
transition: all 250ms ease;
166
}
167
168
.radio input[type="radio"]:checked+.radio-label:before {
169
background-color: #5367FF;
170
box-shadow: inset 0 0 0 4px #f4f4f4;
171
}
172
173
.radio input[type="radio"]:focus+.radio-label:before {
174
outline: none;
175
border-color: #3197EE;
176
}
177
178
.radio input[type="radio"]:disabled+.radio-label:before {
179
box-shadow: inset 0 0 0 4px #f4f4f4;
180
border-color: #b4b4b4;
181
background: #b4b4b4;
182
}
183
184
.radio input[type="radio"]+.radio-label:empty:before {
185
margin-right: 0;
186
}
187
188
/* Radio End */
189
190
@media only screen and (max-width: 325px) {
191
.sip-calculator {
192
height: 560px;
193
}
194
195
h1 {
196
font-size: 1.5em;
197
}
198
}
199
200
@media (max-width: 576px) {
201
body {
202
font-size: smaller;
203
}
204
205
.sip-calculator {
206
width: 100%;
207
padding: 2em;
208
margin: .1em;
209
}
210
}
211
212
/*Groww Logo on mobile*/
213
@media (max-width: 768px) {
214
.groww-logo {
215
width: 100px;
216
height: 25px;
217
}
218
}
JavaScriptcopy
167
1
/* -- THE CALCULATOR CODE -- */
2
var amountSlider = document.getElementById("myAmount");
3
var amountOutput = document.getElementById("inputAmount");
4
var roiSlider = document.getElementById("myRoi");
5
var roiOutput = document.getElementById("inputRoi");
6
var yearSlider = document.getElementById("myYears");
7
var yearOutput = document.getElementById("inputYears");
8
9
amountOutput.innerHTML = amountSlider.value;
10
roiOutput.innerHTML = roiSlider.value;
11
yearOutput.innerHTML = yearSlider.value;
12
13
amountSlider.oninput = function () {
14
amountOutput.innerHTML = this.value;
15
}
16
roiSlider.oninput = function () {
17
roiOutput.innerHTML = this.value;
18
}
19
yearSlider.oninput = function () {
20
yearOutput.innerHTML = this.value;
21
}
22
23
function showValAmount(newVal) {
24
amountSlider.value = newVal;
25
calculateIt();
26
};
27
function showValRoi(newVal) {
28
roiSlider.value = newVal;
29
calculateIt();
30
};
31
function showValYears(newVal) {
32
yearSlider.value = newVal;
33
calculateIt();
34
};
35
36
amountSlider.addEventListener("input", updateValueAmount);
37
roiSlider.addEventListener("input", updateValueRoi);
38
yearSlider.addEventListener("input", updateValueYears);
39
40
function updateValueAmount(e) {
41
amountOutput.value = e.srcElement.value;
42
calculateIt();
43
}
44
function updateValueRoi(e) {
45
roiOutput.value = e.srcElement.value;
46
calculateIt();
47
}
48
function updateValueYears(e) {
49
yearOutput.value = e.srcElement.value;
50
calculateIt();
51
}
52
53
var calculatorMode = 'sip';
54
var heading = document.getElementById("heading");
55
var amountLabel = document.getElementById("amountLabel");
56
57
function changeMode(mode){
58
calculatorMode = mode;
59
heading.innerHTML = mode === 'sip' ? 'SIP Calculator' : 'Lumpsum Calculator';
60
amountLabel.innerHTML = mode === 'sip' ? 'Monthly Investment :' : 'Total Investment :';
61
calculateIt();
62
}
63
64
function calculateIt() {
65
var wealthOutput = document.getElementById("yourWealth");
66
var A = document.sipForm.realAmount.value;
67
var R = document.sipForm.realRoi.value;
68
var N = document.sipForm.realYears.value;
69
var sip = Math.round((Math.pow((1 + (Math.pow((1 + R / 100), (1 / 12)) - 1)), (N * 12)) - 1) / (Math.pow((1 + R / 100), (1 / 12)) - 1) * A);
70
var lumpsum = Math.round(Math.pow((1 + R / 100), N) * A);
71
var finalOutput = calculatorMode === 'sip' ? sip : lumpsum;
72
wealthOutput.innerHTML = "Rs. " + finalOutput; // Print BMI
73
}
74
calculateIt();
75
76
/* -- THE CHART CODE -- */
77
anychart.onDocumentReady(function() {
78
79
// add empty dataset
80
var dataSet = anychart.data.set();
81
82
//populate dataset with data from the calculator
83
[tiv,rent] = calculator();
84
85
var data = dataSet.data([
86
{x: "Total invested value", value: tiv},
87
{x: "Net Return percentage", value: rent}
88
]);
89
90
// add listeners to modify chart accordingly
91
amountSlider.addEventListener("input", updateChartData);
92
roiSlider.addEventListener("input", updateChartData);
93
yearSlider.addEventListener("input", updateChartData);
94
amountOutput.addEventListener("input", updateChartData);
95
roiOutput.addEventListener("input", updateChartData);
96
yearOutput.addEventListener("input", updateChartData);
97
98
// add modification function
99
function updateChartData() {
100
[tiv,rent] = calculator();
101
dataSet.data([
102
{x: "Total invested value", value: tiv},
103
{x: "Net Return percentage", value: rent}
104
]);
105
106
//add title stating the total
107
var totalWealth = tiv + rent;
108
chart.title("Your wealth is " + totalWealth);
109
110
//add total to the legend by adding custome legend item
111
chart.legend().itemsFormatter(function(legendItems) {
112
legendItems.push({
113
text: "Your wealth is " + totalWealth,
114
iconEnabled: false,
115
fontColor: "#455a64",
116
fontWeight: 600
117
});
118
return legendItems;
119
});
120
}
121
122
// create the chart
123
var chart = anychart.pie();
124
125
//add title stating the total
126
var totalWealth = tiv + rent;
127
chart.title("Your wealth is " + totalWealth);
128
129
//add total to the legend by adding custome legend item
130
chart.legend().itemsFormatter(function(legendItems) {
131
legendItems.push({
132
text: "Your wealth is " + totalWealth,
133
iconEnabled: false,
134
fontColor: "#455a64",
135
fontWeight: 600
136
});
137
return legendItems;
138
});
139
140
// add the data
141
chart.data(data);
142
143
// sort elements
144
chart.sort("desc");
145
146
// set legend position
147
chart.legend().position("right");
148
149
// set items layout
150
chart.legend().itemsLayout("vertical");
151
152
// display the chart in the container
153
chart.container('container');
154
chart.draw();
155
});
156
157
// add a function to return needed values
158
function calculator() {
159
var A = document.sipForm.realAmount.value;
160
var R = document.sipForm.realRoi.value;
161
var N = document.sipForm.realYears.value;
162
var sip = Math.round((Math.pow((1 + (Math.pow((1 + R / 100), (1 / 12)) - 1)), (N * 12)) - 1) / (Math.pow((1 + R / 100), (1 / 12)) - 1) * A);
163
var tiv = A * N * 12;
164
var rent = sip - tiv;
165
console.log('test')
166
return [tiv, rent]
167
}