I'm doing a graph with d3, I have two checkboxes, each one refers to a series of data, what I want is when I click on one and it's activated, it shows the data. I already did this method for jqplot, but when it came to updating the data in jqplot it was as easy as using redraw
. Now in d3.js I do not understand very well how to do it. I leave the method:
function mostrarDatos(){
nowData=[]
if($("#eae").prop('checked') == true)
{
nowData.push(eaepunt1[coundata])
}
if($("#arab").prop('checked') == true)
{
nowData.push(arabpunt1[coundata])
}
console.log(nowData)
svg.selectAll("circle")
.data(nowData)
.attr("cx", function(d) {
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
}
Finally add some information, nowData
is the Data Array I want to show. eaepunt1
is the Data Array that contains x
e y
of the graph, this refers to the first checkbox, arabpunt1
is the Data Array of the second checkbox, it also contains x
e y
for the graphic.
The data at the beginning I paint them in this way:
var datos = svg.selectAll("circle")
.data(nowData)
.enter()
.append("circle")
.attr("cx", function(d) {
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
.attr("r", function(d) {
return 5;
})
;
I think I have left all the primary information here, if you have any doubt about something, share it with me and I will edit the question.
EDITED
I have managed to show the data by changing the mostrarDatos()
method in this way:
function mostrarDatos(){
nowData=[]
if($("#eae").prop('checked') == true)
{
nowData.push(eaepunt1[coundata])
}
if($("#arab").prop('checked') == true)
{
nowData.push(arabpunt1[coundata])
}
console.log(nowData)
svg.selectAll("circle")
.data(nowData)
.enter()
.append("circle")
.attr("cx", function(d) {
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
.attr("r", function(d) {
return 5;
})
;
}
But when I uncheck the check the data is still displayed