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

199
Visualizações
How do you change the vertical margin in a vis.js timeline?

In each row of a vis.js timeline there is a margin of 5px. This is set as an inline style programmatically: the height of each row is specified by the library, and so is the top position and transform of each item in the row.

This means that setting these values yourself (for example, with item.style = 'top: 0') fails because they are immediately overwritten by vis.js.

How would I change this margin?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The margin option described in the vis-timeline options list at https://visjs.github.io/vis-timeline/docs/timeline/#Configuration_Options can be used to adjust the margins.

For example the below sets the horizontal and vertical margins for items to 0 pixels. It also sets the axis margin to 5 pixels to place items closer to time axis.

var options = {
    margin : { 
        item: {horizontal:0, vertical:0},
        axis: 5       
    }
};

CSS can then be used to change the height of the items.

.vis-box {
  height: 20px;
}
.vis-range {
  height : 20px;
}

Full example using these settings for a compact view:

// DOM element where the Timeline will be attached
var container = document.getElementById("visualization");

// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet([
  { id: 1, content: "item 1", start: "2021-12-20" },
  { id: 2, content: "item 2", start: "2021-12-14" },
  { id: 3, content: "item 3", start: "2021-12-18" },
  { id: 4, content: "item 4", start: "2021-12-16", end: "2021-12-19" },
  { id: 5, content: "item 5", start: "2021-12-25" },
  { id: 6, content: "item 6", start: "2021-12-27", type: "point" },
]);

// Configuration for the Timeline
var options = {
    margin : { 
        item: {horizontal:0, vertical:0},
        axis: 5       
    }
};

// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
body,
html {
  font-family: sans-serif;
}
.vis-box {
  height: 20px;
}
.vis-range {
  height : 20px;
}
.vis-item {
  font-size: 12px;
}
<script src="https://visjs.github.io/vis-timeline/standalone/umd/vis-timeline-graph2d.min.js"></script>
<link href="https://visjs.github.io/vis-timeline/styles/vis-timeline-graph2d.min.css" rel="stylesheet"/>

<div id="visualization"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Have you tried !important? Example: top: 0 !important;

This will ensure that this property will not be overwritten.

about 4 years ago · Juan Pablo Isaza Relatório
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