下面的代码导致图表中没有数据系列被绘制,实际数据正在加载
rob@workLaptop:~$ cat /path/to/files/data/myFile.txt
1,1
2,1
3,1
爪哇..
import java.util.Vector;
public class Dataset {
private String name;
private Vector<GraphPoint> points;
public Dataset(String nameTemp){
this.name = nameTemp;
this.points = new Vector<GraphPoint>();
}
}
使用 AJAX 从 servlet发送Vector<Dataset>
到 javascript,数据使用序列化response.getWriter().write(new Gson().toJson(datasets));
javascript ..
$(".body").append('<div id="content"><div class="demo-container"><div id="placeholder" class="demo-placeholder"></div></div></div>');
var datasets = JSON.parse(xmlhttp.responseText);
//alert(xmlhttp.responseText);
var plotarea = $("#placeholder");
$.plot(plotarea, [datasets[0].points, datasets[1].points]);
alert(xmlhttp.responseText);
输出 ..
[
{"name":"myFile.txt",
"points":[
{"timestamp":30,"value":100},
{"timestamp":31,"value":101},
{"timestamp":32,"value":110}
]},
{"name":"anotherFile.txt",
"points":[
{"timestamp":1382987630,"value":200},
{"timestamp":1382987631,"value":201},
{"timestamp":1382987632,"value":205}
]}
]