par
Woftys » 27 janv. 2015, 01:31
Alors, voilà mon code actuel:
[javascript]$(function () {
var chart;
$(document).ready(function() {
$.getJSON("valeur.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline',
animation: Highcharts.svg,
marginRight: 130,
marginBottom: 25,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
$.getJSON('valeur.php', function (json) {
series.addPoint(json);
});
}, 1000);
}
}
},
title: {
text: '',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
});[/javascript]
Et je voudrais ajouter un "push" comme ici :
[javascript]series: [{
name: 'Random data',
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: Math.random()
});
}
return data;
}())
}][/javascript]
Mon souci vient du fait qu'il y a un décalage vers la gauche qui s'effectue mais qu'il n'y a pas de nouvelles valeurs qui s'affiche (pas de nouveaux points). Et aussi, dans un second temps j'aimerais intégrer un "push" comme dans le bout de code précédent, mais là je ne vois pas comment faire avec mon "json". J'ai essayé je ne sais combien de trucs différents, sans succès.
Concernant les erreurs, baaaaah, si le code ne fonctionne j'obtiens une page blanche >_<
Alors, voilà mon code actuel:
[javascript]$(function () {
var chart;
$(document).ready(function() {
$.getJSON("valeur.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline',
animation: Highcharts.svg,
marginRight: 130,
marginBottom: 25,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
$.getJSON('valeur.php', function (json) {
series.addPoint(json);
});
}, 1000);
}
}
},
title: {
text: '',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
});[/javascript]
Et je voudrais ajouter un "push" comme ici :
[javascript]series: [{
name: 'Random data',
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: Math.random()
});
}
return data;
}())
}][/javascript]
Mon souci vient du fait qu'il y a un décalage vers la gauche qui s'effectue mais qu'il n'y a pas de nouvelles valeurs qui s'affiche (pas de nouveaux points). Et aussi, dans un second temps j'aimerais intégrer un "push" comme dans le bout de code précédent, mais là je ne vois pas comment faire avec mon "json". J'ai essayé je ne sais combien de trucs différents, sans succès.
Concernant les erreurs, baaaaah, si le code ne fonctionne j'obtiens une page blanche >_<