Я хочу, чтобы шоу о оси X в год, но у меня проблемы. Я использую код, предоставленный на веб -сайте D3. Кто -нибудь может посоветовать? < /P>
// Declare the chart dimensions and margins.
const width = 1140;
const height = 400;
const marginTop = 20;
const marginRight = 20;
const marginBottom = 30;
const marginLeft = 40;
// Declare the x (horizontal position) scale.
const x = d3.scaleUtc()
.domain([new Date("2007-01-01"), new Date("2023-01-01")])
.range([marginLeft, width - marginRight]); //shows one tick every other year
x.ticks(d3.utcYear.every(1)); //my code, but it doesn't work. x-axis still shows one tick every other year
// Declare the y (vertical position) scale.
const y = d3.scaleLinear()
.domain([0, 100])
.range([height - marginBottom, marginTop]);
// Create the SVG container.
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
// Add the x-axis.
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom})`)
.call(d3.axisBottom(x));
// Add the y-axis.
svg.append("g")
.attr("transform", `translate(${marginLeft},0)`)
.call(d3.axisLeft(y));
// Append the SVG element.
container.append(svg.node());
Подробнее здесь: https://stackoverflow.com/questions/797 ... very-other