differencesChart = {
const svg = d3.select(DOM.svg(width, height));
svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#EEEEEE");
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const colorMapping = [
{
name: "Training",
color: "blue"
},
{
name: "Test",
color: "orange"
}
];
svg.append("g")
.attr("stroke", "blue")
.attr("fill", "blue")
.selectAll("circle")
.data(trainingData)
.join("circle")
.attr("cx", d => x(d.YearsExperience))
.attr("cy", d => y(d.Salary))
.attr("r", 2);
svg.append("g")
.attr("stroke", "orange")
.attr("fill", "orange")
.selectAll("circle")
.data(testData)
.join("circle")
.attr("cx", d => x(d.YearsExperience))
.attr("cy", d => y(d.Salary))
.attr("r", 2);
const xAxisMin = d3.min(trainingData, d => Math.floor(d.YearsExperience));
const xAxisMax = d3.max(trainingData, d => Math.floor(d.YearsExperience));
svg.append('line')
.attr('x1',x(xAxisMin))
.attr('x2',x(xAxisMax))
.attr('y1',y(gradient * xAxisMin + yIntercept))
.attr('y2',y(gradient * xAxisMax + yIntercept))
.attr("stroke", "darkgrey")
var legend = svg.selectAll(".legend")
.data(colorMapping)
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(-10," + ((i * 20) + 10) + ")"; });
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", d => d.color);
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d.name;})
svg.append("g")
.append("text")
.attr("x", width/2)
.attr("y", 50)
.attr("font-size", "1.5em")
.attr("font-weight", "300")
.style("text-anchor", "middle")
.text("Salary from Years Experience");
return svg.node();
}