以下是使用d3.v5在我的图表上的yAxis代码:
let x = d3.scaleTime()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
let y = d3.scaleSymlog()
.domain([0, d3.max(data, d => d.Confirmed)]).nice()
.range([height - margin.bottom, margin.top])
let line = d3.line()
.defined(d => !isNaN(d.value))
.x(d => x(d.date))
.y(d => y(d.value))
let xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
let yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y))
let svg = d3.select('#MultiLineLogChart').select("svg")
svg.attr("viewBox", [0, 0, width, height])
.attr("fill", "none")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
这是我的对数图表的链接:https://covid19wiki.info/country/Canada
慕村9548890
相关分类