Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
DV-HW4
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
DV-HW4
Commits
f8041687
Commit
f8041687
authored
Jan 10, 2025
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add start year to area chart
parent
6c16b023
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
index.html
index.html
+1
-1
main.ts
src/ts/main.ts
+14
-10
No files found.
index.html
View file @
f8041687
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<div
class=
"heading"
>
<div
class=
"heading"
>
<p
class=
"title"
>
S
&
P 500 Index
</p>
<p
class=
"title"
>
S
&
P 500 Index
</p>
<span
class=
"select-text"
>
Start year
</span><input
type=
"number"
min=
"2015"
max=
"2020"
value=
"2015"
<span
class=
"select-text"
>
Start year
</span><input
type=
"number"
min=
"2015"
max=
"2020"
value=
"2015"
id=
"area-chart-year-input"
>
onkeydown=
"return false;"
id=
"area-chart-year-input"
>
</div>
</div>
<svg
id=
"area-chart"
></svg>
<svg
id=
"area-chart"
></svg>
</div>
</div>
...
...
src/ts/main.ts
View file @
f8041687
...
@@ -52,7 +52,20 @@ import * as d3 from 'd3';
...
@@ -52,7 +52,20 @@ import * as d3 from 'd3';
/**
/**
* Load data from CSV file asynchronously and render scatter plot
* Load data from CSV file asynchronously and render scatter plot
*/
*/
const
areaChart
=
new
AreaChart
(
new
ChartConfiguration
(
"#area-chart"
));
const
areaChart
=
new
AreaChart
(
new
ChartConfiguration
(
"#area-chart"
));
let
areaChartData
:
any
[];
d3
.
select
(
'#area-chart-year-input'
)
.
on
(
'input'
,
function
()
{
// Get the current value of the input
let
value
=
d3
.
select
(
this
).
property
(
'value'
);
value
=
+
value
;
console
.
log
(
areaChartData
[
0
].
date
);
const
areaChartFilteredData
=
areaChartData
.
filter
(
item
=>
item
.
date
.
getFullYear
()
>=
value
);
areaChart
.
data
=
areaChartFilteredData
;
areaChart
.
updateVis
();
});
d3
.
csv
(
'/data/sp_500_index.csv'
)
d3
.
csv
(
'/data/sp_500_index.csv'
)
.
then
(
inputData
=>
{
.
then
(
inputData
=>
{
...
@@ -62,17 +75,8 @@ d3.csv('/data/sp_500_index.csv')
...
@@ -62,17 +75,8 @@ d3.csv('/data/sp_500_index.csv')
d
.
close
=
+
d
.
close
;
d
.
close
=
+
d
.
close
;
});
});
areaChartData
=
inputData
;
areaChart
.
data
=
inputData
;
areaChart
.
data
=
inputData
;
areaChart
.
updateVis
();
areaChart
.
updateVis
();
})
})
.
catch
(
error
=>
console
.
error
(
error
));
.
catch
(
error
=>
console
.
error
(
error
));
setTimeout
(()
=>
{
const
dateParser
=
d3
.
timeParse
(
"%Y-%m-%d"
);
let
t
:
any
=
{
date
:
'2025-10-29'
,
close
:
0
};
t
.
date
=
dateParser
(
t
.
date
);
t
.
close
=
+
t
.
close
;
areaChart
.
data
.
push
(
t
);
areaChart
.
updateVis
();
},
1000
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment