Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

80
Vistas
Epoch.js with websocket is too slow to update

I am trying to write real-time chart with Epoch.js by using websocket to get data. My current goal is to allow user to pause/play the chart by pressing the button. The problem is that the response is too slow when pressing the button.

The javascript code below shows that every time the button is pressed the value 1000 or 500 is put and drawn on timechart alternatively.

var ws = new WebSocket("ws://localhost:8000/publish");
var data = [
{ label: "Series 1", values: [] }
];
var lineChart = $('#graph').epoch({
type: 'time.line',
data: data,
axes: ['left', 'right', 'bottom']
});

var pushPoint = function(isplaying) {
ws.onmessage = function(msg) {
  if(isplaying){
    value=1000
  }
  else{
    value=500
  }
  var current = [
    { time:time, y: value }
  ]
  lineChart.push(current);
  };
};

$('button').on('click', function(e) {
if (isplaying) {/* will pause */
  $(e.target).text('play');
  isplaying=false;
}
else { /* will play */
  $(e.target).text('Pause');
  isplaying=true;
}
pushPoint(isplaying)
}

(apologize for the messy code as I am new to js) The problem is that the value in the chart won't change as soon as the button is pressed, which takes 7-8seconds that is too slow. How could I solve this problem? Any advice would be welcome. Thank you.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda