Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
scaleTime method not compute the value in right way

I am working with d3.js and draw scatter plot chart using the scaleTime to compute the values on x-axis and y-axis but the scales are not computing the data in right way. ( 1 )The interval of seconds in the y-axis should be only 15 seconds and that should start at 37:00. ( 2 ) There should be a slight gap at the beginning of the x-axis and the tick at the end of the x-axis should have a 2016 value.

as shown in the picture below

retriveData();

async function retriveData() {
 let response = await fetch(
   "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/cyclist-data.json"
 );
 let json = await response.json();
 chart(json);
}

function chart(dataset) {
 const width = 800,
   height = 500,
   padding = 60;

 let svg = d3
   .select("body")
   .append("svg")
   .style("width", width)
   .style("height", height);

 const parsedDate = d3.timeParse("%Y");

 const dates = [];
 for (let i = 0; i < dataset.length; i++) {
   dates.push(parsedDate(dataset[i].Year));
 }

 const extentDate = d3.extent(dates);

 const xScale = d3
   .scaleTime()
   .domain(extentDate)
   .range([padding, width - padding]);

 const parsedTime = d3.timeParse("%M:%S");

 const minutes = [];
 
 for (let i = 0; i < dataset.length; i++) {
   minutes.push(parsedTime(dataset[i].Time));
 }

 const extentTime = d3.extent(minutes).sort((a, b) => b - a);

 const yScale = d3
   .scaleTime()
   .domain(extentTime)
   .range([height - padding, padding]);

 let format = d3.timeFormat("%M:%S");

 const xAxis = d3.axisBottom(xScale);
 const yAxis = d3.axisLeft(yScale).tickFormat(format);

 svg
   .append("g")
   .attr("transform", `translate(0,${height - padding})`)
   .call(xAxis);

 svg.append("g").attr("transform", `translate(${padding},0)`).call(yAxis);
}



[solution][1]


 [1]: https://i.stack.imgur.com/D40dF.png
about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda