tooltip text

This commit is contained in:
Sam Hadow 2024-01-23 17:51:14 +01:00
parent 5425f24698
commit 6e458bf6a7

View File

@ -1,7 +1,7 @@
// set the margins of the graph // set the margins of the graph
const margin = { const margin = {
top: 10, top: 10,
right: 30, right: 60,
bottom: 30, bottom: 30,
left: 30 left: 30
}; };
@ -16,7 +16,7 @@ window.onresize = function(){ location.reload(); }
d3.csv('http://127.0.0.1/output.csv', d => { d3.csv('http://127.0.0.1/output.csv', d => {
return { return {
date: new Date(d.h_timestamp.replace(' ', 'T')).getTime(), date: new Date(d.h_timestamp.replace(' ', 'T')),
value: parseFloat(d.price.replace('$', '')), value: parseFloat(d.price.replace('$', '')),
skuid: d.skuid, skuid: d.skuid,
currency: d.currency currency: d.currency
@ -169,9 +169,11 @@ d3.csv('http://127.0.0.1/output.csv', d => {
// Interaction functions // Interaction functions
const mouseover = function(event, d) { const mouseover = function(event, d) {
// var formatted_date = `${d.date.getDate()}-${d.date.getMonth()}-${d.date.getFullYear()}`;
var formatted_date = d.date.toISOString().split('T')[0]
Tooltip Tooltip
.style("opacity", 1) .style("opacity", 1)
.html(d.value + " " + d.currency) .html(formatted_date + "<br />" + d.value + " " + d.currency)
.style("left", (event.pageX + 10) + "px") .style("left", (event.pageX + 10) + "px")
.style("top", (event.pageY + 10) + "px"); .style("top", (event.pageY + 10) + "px");
}; };