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

171
Visualizações
Add plotbonds to Gaps defined by GapSize in Highcharts

I am trying to add background color to gaps in data to be more visible on large intervals, I know that I can do that by adding plotbonds with the color I want, the problem is I don't have the start and end of the gap because it is created by defining the GapSize and GapUnit (no dates with null data, juste a gap in the dates). I tried adding the plotbonds by calculating the difference between the dates and comparing it to the tickInterval but no luck so far,

here is an example of gaps set with gapsize

 plotOptions: {
        series: {
            gapSize: 1
        }
    }

https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/stock/plotoptions/series-gapsize

Is there a simpler way of doing this ?

thanks

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

0

Highcharts internally adds null points to create gaps. You can get the calculated null points and based on their values, create plot-bands.

For example:

let plotBands = [];
let allowChartUpdate = true;

(function(H) {
    H.wrap(H.seriesTypes.area.prototype, 'getGraphPath', function(proceed, points) {
        const xAxis = this.xAxis;
        plotBands = [];

        points.forEach((p, index) => {
            if (p.isNull) {
                plotBands.push({
                    from: points[index - 1] ? points[index-1].x : xAxis.min,
                    to: points[index + 1] ? points[index+1].x : xAxis.max,
                    color: 'red'
                });
            }
        });

        return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    });
}(Highcharts));

Highcharts.stockChart('container', {
    chart: {
        type: 'area',
        events: {
            render: function() {
                // prevent infinity loop
                if (allowChartUpdate) {
                    allowChartUpdate = false;
                    this.xAxis[0].update({plotBands});
                    allowChartUpdate = true;
                }
            }
        }
    },
    ...
});

Live demo: https://jsfiddle.net/BlackLabel/jz0n28om/

API Reference: https://api.highcharts.com/highcharts/xAxis.plotBands

Docs: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

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