Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda