I would know how to create two interactive graphs using d3.js,I mean for example one line chart interacting with a scatter plot by clicking on a value of the line chart and visualizing the corresponding one on the scatter plot.How can i obtain such an effect?Basically I dont't know how to call a mouseover function on graph A and seeing the effect of this function on graph B.
d3.csv("resources/diffusionesitiweb10anni.csv",function(data){
dataset = data;
data.forEach(function(d) {
d["Anno"] = parseDate(d["Anno"].toString());
});
yAxis.tickFormat(function(d){return d + "%"});
yScale.domain([0,d3.max(dataset,function(d){
return +d["Italia"];
})]);
xScale.domain(d3.extent(data,function(d){
return +d["Anno"];
}));
/***** provo line chart ********/
svg1.append("g")
.attr("class","x axis")
.attr("transform","translate(0," + height +")")
.call(xAxis);
svg1.append("g")
.attr("class","y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Percentage");
svg1.append("path")
.attr("class","line")
.attr("d",line(dataset))
.style("stroke","black")
.transition().duration(2500).attrTween("d",pathTween);
function pathTween() {
var interpolate = d3.scale.quantile()
.domain([0,1])
.range(d3.range(1, data.length + 1));
return function(t) {
return line(data.slice(0, interpolate(t)));
};
}
svg1.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx",function(d){
return xScale(d["Anno"]);
})
.attr("cy",function(d){
return yScale(d["Italia"]);
})
.attr("r",3)
.on('mouseover', tip.show).on('mouseout', tip.hide);
});
This is the first graph(linechart),and the following is the second one
d3.csv("resources/utilizzoInternet.csv",function(data){
datiInternet = data;
var margin = {top: 20, right: 20, bottom: 30, left: 40};
width = containerWidth - margin.left - margin.right,
height = containerHeight - margin.top - margin.bottom;
var parseDate = d3.time.format("%Y").parse;
var xScale = d3.time.scale().range([0,width]);
var yScale = d3.scale.linear().range([height,0]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom");
var yAxis = d3.svg.axis().scale(yScale).orient("left");
svg2=d3.select("#LineChart")
.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 + ")");
yScale.domain([0,d3.max(datiInternet,function(d){
return +d["Totale"];
})]);
xScale.domain(d3.extent(data,function(d){
return +d["Anno"];
}));
svg2.selectAll("circle")
.data(datiInternet)
.enter()
.append("circle")
.attr("cx",function(d){
return xScale(d["Anno"]);
})
.attr("cy",function(d){
return yScale(d["Totale"]);
})
.attr("r", function(d) {
return Math.sqrt(d["Totale"]);
});
});
The two graph are made by two different csv file,what i would like to do is to pass the mouse over a point in the line chart,and have this point displayed on the second chart which is a scatter plot.How can I implement such a "mouseover" function? Thanks in advance,hope that now is more completed and clear.
Working JSFiddle: http://jsfiddle.net/mirko89/ahrdormr/5/