私はphpから取得した2つの配列を1つの2D Javascript配列に入れています。これを使用して Google Chart DataTable を自動入力しようとしていますが、これまでのところ成功していません。私が考えることができる唯一のことは、おそらく配列は ix MxN 次元ですが、関数には NxM 配列が必要ですか?
最初の配列が数値で構成されているため、機能しませんか?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Pressure Monitor</title>
<script type="text/javascript">
var samptable = new Array();
samptable[0] = new Array(2);
samptable[0,0]= nbsamples; //first array obtained from php
samptable[0,1]= samples; //second array obtained from php. both are merged into a 2d array
</script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
//var data;
function drawVisualization() {
var data = google.visualization.arrayToDataTable(samptable[0]);
// Create and draw the visualization.
new google.visualization.LineChart(document.getElementById('visualization')).
draw(data, {curveType: "function",
width: 500, height: 400,
vAxis: {maxValue: 10}}
);
}
//function draw(){
//}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="width: 800px; height: 400px;"></div>
</body>
</html>
nbsamples とサンプルを取得するために使用されるコード:
echo '<script type="text/javascript">';
echo 'var samples = new Array("', join($ydata,'","'), '");';
echo 'var nbsamples = new Array("', join($nbsamples,'","'), '");';
echo '</script>';