0

When I am creating the graph with the highchart I intend to print the javascript variable inside the subtitle.

code JS:

for (var key2 in data5) {
    if (data5.hasOwnProperty(key2)) {
    items2 = items2.concat(data5[key2]);
}
   nome2 = items2[0]
   qtd2 = items2[1]
  }   
   qtd3 = qtd2 - qtd1
   
   qtd4 = qtd3 / 100

$('#container').highcharts({
        chart: {
            renderTo: 'container',
            type: 'column',
    options3d: {
      enabled: true,
      alpha: 0,
      beta: 0,
      depth: 20,
    }
        },
        title: {
            text: 'AVALIAÇÃO CONSUMOS LUVAS'
        },
        subtitle: {
            text: '<strong>Notas:</strong> Estamos a comparar os meses de janeiro/fevereiro com o mês de junho (mês em que voltamos à "normalidade", em que cada colaborador efetuou registo/fez requisição. Não estamos a considerar os meses de março, abril e maio, por serem meses em que as luvas ficaram à descrição e nem todos os colaboradores efetuaram registo na folha consoante pedimos. O normal seria o junho ser idêntico a janeiro ou fevereiro. No entanto cada colaborador deve avaliar/avaliar-se mês a mês. De janeiro/fevereiro para junho o consumo aumentou em qtd3 luvas = qtd4 caixas.'
        }

Within the subtitle I intend to echo the variable qtd3 and qtd4 but I'm not getting it. Can you help?

ambianBeing
  • 3,449
  • 2
  • 14
  • 25
Bruno
  • 801
  • 5
  • 11
  • 1
    What you mean by "_echo the variable_"? – palaѕн Jul 06 '20 at 14:25
  • Does this answer your question? [How to interpolate variables in strings in JavaScript, without concatenation?](https://stackoverflow.com/questions/3304014/how-to-interpolate-variables-in-strings-in-javascript-without-concatenation) – ambianBeing Jul 06 '20 at 15:42

2 Answers2

1

Combine the variable into the string properly:

 text: 'o consumo aumentou em '+qtd3+' luvas = '+qtd4+' caixas.'
Phaelax z
  • 1,814
  • 1
  • 7
  • 19
1

Or you can use the ES6 template strings feature.

Demo: https://jsfiddle.net/BlackLabel/jrukoxb0/

subtitle: {
    text: `test subtitle ${variable}`
},
Sebastian Wędzel
  • 11,417
  • 1
  • 6
  • 16