Conditional within series of HighCharts

2

How do I condition the number of series I want displayed on my Highcharts ?

That is:

  • If the value% co_of% is equal to 1 that shows the following:

series: [{
  name: '<span style="font-size: 65%">' + datos.fecha[0] + '</span>',
  color: '#ff6600',
  data: [datos[0][0], datos[0][1], datos[0][2], datos[0][3], datos[0][4]],
  pointPlacement: 'off'
}]
  • If the value% co_of% is equal to 2 then:

series: [{
  name: '<span style="font-size: 65%">' + datos.fecha[0] + '</span>',
  color: '#ff6600',
  data: [datos[0][0], datos[0][1], datos[0][2], datos[0][3], datos[0][4]],
  pointPlacement: 'off'
},{
  name: '<span style="font-size: 65%">' + datos.fecha[1] + '</span>',
  color: '#0f6600',
  data: [datos[1][0], datos[1][1], datos[1][2], datos[1][3], datos[1][4]],
  pointPlacement: 'off'
}]
    
asked by Daniel Garcia 16.03.2017 в 22:42
source

1 answer

0

From what I understood: You want to be able to choose what number of series to show in the rendering of the graphic.

  • Save your series with a variable before rendering your graphic.
  •     var $series =  [{
          name: '<span style="font-size: 65%">' + datos.fecha[0] + '</span>',
          color: '#ff6600',
          data: [datos[0][0], datos[0][1], datos[0][2], datos[0][3], datos[0][4]],
          pointPlacement: 'off'
        },{
          name: '<span style="font-size: 65%">' + datos.fecha[1] + '</span>',
          color: '#0f6600',
          data: [datos[1][0], datos[1][1], datos[1][2], datos[1][3], datos[1][4]],
          pointPlacement: 'off'
        }];
  • Use slice to show only the number of series you want:
  •     var $series = [{..}, {..}]// muchos elementos
        
        // aqui codigo del renderizado
        series: $series.splice(0,2); // El 0 corresponde al elemento inicial, el 1 sería el elemento final (Recuerda que los arreglos(array) comienzan con 0.
        
    answered by 19.03.2017 в 10:20