I get an answer from a friend but i still have problems, I have a graphe with dots, and actually when i put the mouse over a dot, this one is going red as expected , but i didnât succed to get it back as the original color blue. All dot that i go over stays in red. And i get the following console error each time i go out of one circle:
<!-- Add a svg area, empty -->
<div id="scatter_area"></div>
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v7.js"></script>
<script>
// set the dimensions and margins of the graph
var margin = {top: 10, right: 40, bottom: 30, left: 30},
width = 450 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
// append the svg object to the body of the page
var svG = d3.select("#scatter_area")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Create data
var data = [ {x:10, y:20}, {x:40, y:90}, {x:80, y:50} ]
// X scale and Axis
var x = d3.scaleLinear()
.domain([0, 100]) // This is the min and the max of the data: 0 to 100 if percentages
.range([0, width]); // This is the corresponding value I want in Pixel
svG
.append('g')
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// X scale and Axis
var y = d3.scaleLinear()
.domain([0, 100]) // This is the min and the max of the data: 0 to 100 if percentages
.range([height, 0]); // This is the corresponding value I want in Pixel
svG
.append('g')
.call(d3.axisLeft(y));
function logMeasurement(event, d){
var a = d.measurement
const x0 = d.date
console.log("Température point :",a)
console.log("Date",x0)
var formatDate = d3.timeFormat("%Y-%m-%d %H:%M:%S") //Convertie la valeur x0 au format souhaité Y%m%d
var w=formatDate(x0)
console.log("w",w)
var bisectDate = d3.bisector(d => d.date).right
i = bisectDate(data, w) //Appel la var bisectDate
console.log("i",i)//Pointeur de l'array
//console.log("Recherche",slices[0].values[i-1]);
}
// Add 3 dots for 0, 50 and 100%
svG
.selectAll("whatever")
.data(data)
.enter()
.append("circle")
.attr("cx", function(d){ return x(d.x) })
.attr("cy", function(d){ return y(d.y) })
.attr("r", 7)
d3.selectAll('circle')
.style("fill", "blue")
.attr("class","point")
.style("opacity", 1)
.on("mouseover", function(event) {
style("fill", "blue")
style("opacity", 0)
style("display", null);
})
.on("mouseout", function(event) {
style("display", "none")
style("opacity", 0)
style("fill", "blue");
})
.on('mouseover', function(e, d) {
//d3.selectAll('circle')
d3.select(this)
.on("mousemove", (event, d) => logMeasurement(event, d))
.style("fill", "red");
//.style("opacity", 0);
})
</script>