Je test les Highcharts et Sotckcharts dans le cadre d'un projet, mais je n'arrive pas à afficher mes données.
Voici mon code:
Code : Tout sélectionner
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>TEST HIGHCHARTS</title>
</head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="https://code.highcharts.com/stock/highstock.js" type="text/javascript"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
AffichageGraph();
});
function AffichageGraph() {
$.ajax({
type: "GET",
url: 'XML/PackDO_Datas_Graphs.xml',
dataType: 'xml',
success: readXML,
data: {
_rnd: new Date().getTime()
}
});
}
function readXML(xml) {
var options = {
rangeSelector: {
buttonTheme: { width: 70 },
buttons: [{ type: 'day', count: 1, text: '1 jour' },
{ type: 'day', count: 7, text: '7 jours' },
{ type: 'month', count: 1, text: '1 mois' },
{ type: 'all', count: 1, text: 'Tous'}],
inputEnabled: true,
selected: 3
},
lang: {
months: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
weekdays: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
shortMonths: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'],
decimalPoint: ',',
resetZoom: 'Reset zoom',
resetZoomTitle: 'Reset zoom à 1:1',
downloadPNG: 'Télécharger au format PNG',
downloadJPEG: 'Télécharger au format JPEG',
downloadPDF: 'Télécharger au format PDF',
downloadSVG: 'Télécharger au format SVG',
exportButtonTitle: 'Exporter image ou document',
printButtonTitle: 'Imprimer le graphique',
loading: 'Chargement...'
},
//Informations concernant le graphe en générales
chart: { renderTo: 'container', type: 'spline' },
//Informations concernant le graphe en générales
title: { text: 'Mesures des hauteurs d\'eau des DO' },
//Informations concernant l'axe X
xAxis: {
type: 'datetime'
},
//Informations concernant l'axe Y
yAxis: {
min: 0,
title: { text: 'Hauteur d\'eau' },
labels: { overflow: 'justify' }
},
//Informations concernant les séries de données
series: [{
name: 'Sonde S1',
data: []
}],
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
dateFormat: { format: '%d/%m/%Y %H:%MM:%S' },
//Informations concernant les tooltips
tooltip: {
formatter: function () {
var s = '<b>' + this.x.toLocaleFormat('%d/%m/%Y %H:%M:%S') + '</b>';
$.each(this.points, function (i, point) {
var unit = {
'Sonde S1': ' mètres'
}[this.point.series.name];
s = s + '<br/>';
s = s + '<span style="color:' + point.series.color + '">' + point.series.name + ': </span>';
s = s + '<b>' + Highcharts.numberFormat(point.y, 5, ",", " ") + '</b> ';
s = s + unit;
});
return s;
}
}
};
var $xml = $(xml); //On définie la variable xml par son contenu
$(xml).find('dsGraphes > GET_DATAS').each(function () {
var dte = new Date($(this).find('DTE').text());
options.series[0].data.push({
x: dte,
y: parseFloat($(this).find('VAL').text())
});
});
var chart = new Highcharts.StockChart(options);
}
</script>
<body>
<div id="container" style="width:800px; height:400px; margin:auto;"></div>
</body>
</html>
Code : Tout sélectionner
<?xml version="1.0" standalone="yes"?>
<dsGraphes xmlns="http://tempuri.org/dsGraphes.xsd">
<GET_DATAS>
<DTE>2015-07-01T00:00:00+02:00</DTE>
<VAL>0.11</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T01:00:00+02:00</DTE>
<VAL>0.11</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T02:00:00+02:00</DTE>
<VAL>0.10</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T02:14:21+02:00</DTE>
<VAL>0.10</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T03:00:00+02:00</DTE>
<VAL>0.11</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T04:00:00+02:00</DTE>
<VAL>0.11</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T05:00:00+02:00</DTE>
<VAL>0.11</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T06:00:00+02:00</DTE>
<VAL>0.14</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T07:00:00+02:00</DTE>
<VAL>0.13</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
<GET_DATAS>
<DTE>2015-07-01T08:00:00+02:00</DTE>
<VAL>0.15</VAL>
<ID_POS>S1</ID_POS>
</GET_DATAS>
</dsGraphes>
Merci d'avance.