dygraph のデータの動的フェッチで問題に直面しています。
私のコードは次のようになります
var SensorID=$('.sensor-selected').attr('title');
var Sensor_Name=$('.sensor-selected').attr('name');
var Sensor_Type=$('.sensor-selected').attr('typ');
var begin=$('#fromdate').val();
var end=$('#todate').val();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
g = new Dygraph(
document.getElementById("graph"),
"file.csv", //change with xmlhttp.responseText
{
labels:["Date",Sensor_Type],
title: Sensor_Name,
ylabel: Sensor_Type,
legend: 'always',
labelsDivStyles: { 'textAlign': 'right' },
showRangeSelector: true,
xAxisLabelWidth: 80,
xValueFormatter: Dygraph.dateString_,
axes: {
x: {
ticker: function (a, b, pixels, opts, dygraph, vals) {
return Dygraph.getDateAxis(a, b, Dygraph.DECADAL, opts, dygraph);
},
axisLabelFormatter: function (val, granularity, opts, dygraph) {
return formatDate(toDateTime(val));
}
}},
xValueParser: function(x) { return 1000*parseInt(x); },
xTicker: Dygraph.dateTicker
}
);
}
}
xmlhttp.open("GET","fetcher.php?SensorID="+SensorID+"&begin="+begin+"&end="+end,true);
xmlhttp.send();
}
csv ファイルを xmlhttp.responseText で変更すると、コードが狂ってしまいます。列の番号がラベルの番号と等しくない、または yAxis が定義されていない、または「2013-11-11」が日付のように解析されていないと表示されることがあります。
その代わり。Ajax 応答を静的な方法で配置すると、それが受け入れられます。
"2013-11-11 12:22:22,22\n" + .... または引用符なしまたは \n なしのような多くの形式を試しました。何も機能しません。
私は何が欠けていますか?繰り返しますが、引用されたような静的データはすべて問題ありません。
たぶん、jquery ソリューションを提案できます。