AJAX - como actualizar una variable php en un grafico

 
Vista:

como actualizar una variable php en un grafico

Publicado por german (2 intervenciones) el 26/09/2018 19:41:21
hola quisiera hacer la siguiente consulta tengo el siguiente codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<script type='text/javascript'>
 
Highcharts.chart('container', {
  chart: {
    type: 'spline',
    animation: Highcharts.svg, // don't animate in old IE
    marginRight: 10,
    events: {
 
      load: function () {
 
        // set up the updating of the chart each second
        var series = this.series[0];
        setInterval(function () {
          var x = (new Date()).getTime(), // current time
 
            y   = <?php echo $so2;?>;
 
          series.addPoint([x, y], true, true);
        }, 1000);
      }
    }
  },
 
  time: {
    useUTC: false
  },
 
  title: {
    text: 'Datos Cems'
  },
  xAxis: {
    type: 'datetime',
    tickPixelInterval: 150
  },
  yAxis: {
    title: {
      text: 'valoeres'
    },
    plotLines: [{
      value: 0,
      width: 1,
      color: '#808080'
    }]
  },
  tooltip: {
    headerFormat: '<b>{series.name}</b><br/>',
    pointFormat: '{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}'
  },
  legend: {
    enabled: false
  },
  exporting: {
    enabled: false
  },
  series: [{
    name: 'so2',
    data: (function () {
      // generate an array of random data
      var data = [],
        time = (new Date()).getTime(),
        i;
 
        for (i = -19; i <= 0; i += 1) {
        data.push({
          x: time + i * 1000,
          y:<?php echo $so2;?>
		  });
 
      }
 
      return data;
    }())
  }]
});
</script>
este codigo es un grafico en tiempo real el cual me muestra el valor de una variable php el problema es que no actualiza el valor tengo entendido que devo usar ajax sin embargo solo se traer un div de un archivo externo en ajax
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de santi
Val: 13
Ha aumentado 1 puesto en AJAX (en relación al último mes)
Gráfica de AJAX

como actualizar una variable php en un grafico

Publicado por santi (6 intervenciones) el 27/09/2018 00:33:18
Hola,

la verdad que sin saber el valor del php es difícil pero si quieres refrescar cada cierto tiempo utiliza setInterval.

Aquí un ejemplo de un contador que suma + 1 cada segundo:

1
2
3
4
5
6
7
8
9
//html
<p>1</p>
jQuery
var num = 1;
var txt = $('p').text();
setInterval(function(){
	$('p').text(parseInt(txt)+num);
	num = num+1;
}, 1000);

Eso sí, está hecho con jQuery...

Prueba
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar