I would like to add a button or a pull down menu to change the left y axis from absolute values to percentages. I found this:
So they use:
var xAxis = d3.axisBottom(xScale)
.tickFormat(d => Math.round(d*100/d3.max(data)) + "%");
var gX = svg.append("g")
.attr("transform", "translate(0," + (h - padding) + ")")
.call(xAxis);
I use
var axLft = g.append("g")
.attr('id', 'y-axis')
.call(d3.axisLeft(yScale));
The combination gives some results, but there is still an error message.
function NumtoPerc(){
var axLft = g.append("g")
.attr('id', 'y-axis')
.call(d3.axisLeft(yScale))
.tickFormat(d => Math.round(d*100/d3.max(dataset1)) + "%")
//.call(axLft)
}
It should delete the old writings of course. There are two ways, one click = to percentages, 2nd click = back to absolute.
Or use the pull down menu and depending on the option that version is displayed.
Also trying to add tooltips like this:
var tooltip = d3.select("svg")
.append("g")
.style("opacity", 0)
.attr("class", "tooltip")
.style("background-color", "white")
.style("border", "solid")
.style("border-width", "1px")
.style("border-radius", "5px")
.style("padding", "10px")
var mouseover = function(d) {
tooltip
.style("opacity", 1)
}
var mousemove = function(d) {
tooltip
.html("Value" + xScale(d[0]))
.style("left", (d3.mouse(this)[0]+90) + "px") // It is important to put the +90: other wise the tooltip is exactly where the point is an it creates a weird effect
.style("top", (d3.mouse(this)[1]) + "px")
}
// A function that change this tooltip when the leaves a point: just need to set opacity to 0 again
var mouseleave = function(d) {
tooltip
.transition()
.duration(200)
.style("opacity", 0)
}
But it doesn’t work.