Jquery 尝试从json文件中加载带有我的温度数据的标志
正在尝试从json文件加载带有我的温度数据的标志 下面的代码适用于加载多个系列的温度数据,但我不知道如何以相同的方式添加标记 有什么想法吗Jquery 尝试从json文件中加载带有我的温度数据的标志,jquery,highstock,Jquery,Highstock,正在尝试从json文件加载带有我的温度数据的标志 下面的代码适用于加载多个系列的温度数据,但我不知道如何以相同的方式添加标记 有什么想法吗 $.each(names, function(i, name) { //this will go thru each location and load the json data to be charted, ie //json_hs_temps.php?location=outside1 <-- temperature dat
$.each(names, function(i, name) {
//this will go thru each location and load the json data to be charted, ie
//json_hs_temps.php?location=outside1 <-- temperature data
//json_hs_temps.php?location=inside <-- temperature data
//json_hs_temps.php?location=owntracks <-- flag data
$.getJSON("jsonloaddata.php?location="+ name.toLowerCase(), function(data) {
console.log( "success with grabing json data for " + name.toLowerCase());
if(name != 'owntracks'){
//temperature data, outside1, inside
seriesOptions[i] = {
name: name + ' Temperature',
data: data,
color: colors[i],
id: 'dataseries',
type: 'line'
};
} else {
//flags or events, enter/leave house
seriesOptions[i] = ({
type: 'flags',
showInLegend: true,
shape: 'circlepin',
onSeries: 'dataseries',
data: data
});
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
});
为“owntracks”返回的JSON数据
[{"x":1405584416,"title":"1","text":"matthew enter home"},{"x":1405584884,"title":"1","text":"joanne enter home"},{"x":1405597925,"title":"1","text":"joanne enter home"},{"x":1405621940,"title":"1","text":"joanne enter home"},{"x":1405605734,"title":"1","text":"joanne enter home"},{"x":1405616039,"title":"1","text":"joanne enter home"},{"x":1405629503,"title":"1","text":"joanne enter home"},{"x":1405632049,"title":"0","text":"joanne leave home"},{"x":1405634418,"title":"0","text":"matthew leave home"}]
它工作的屏幕截图,很好,除了旗帜!
更新--立即工作
因此,在尝试添加标志之前,JSON文件没有完全加载
已改为使用ajax调用,并在继续之前等待调用完成
我已经把完整的代码放在github上,上面的链接
我正在使用ajax调用来获取温度数据的示例,标记数据的方式与此相同,但我会等待所有温度数据加载完毕
$.ajax({
url:"jsonloaddata.php?interval="+interval+"&location="+ name.toLowerCase()+"&querytype="+querytype.toLowerCase(),
dataType:'json',
async:false,
success:function(data) {
// do stuff.
console.log( "success with grabing json data for " + name.toLowerCase());
seriesOptions[i] = {
name: name + ' Temperature',
data: data,
color: colors[i],
id: 'dataseries',
type: 'line',
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
valueDecimals: 1
}
};
}
})
$.ajax({
url:“jsonloaddata.php?interval=“+interval+”&location=“+name.toLowerCase()+”&querytype=“+querytype.toLowerCase()”,
数据类型:'json',
async:false,
成功:功能(数据){
//做事。
log(“为“+name.toLowerCase()”获取json数据成功);
系列选项[i]={
名称:名称+温度,
数据:数据,
颜色:颜色[i],
id:'数据系列',
键入:“行”,
工具提示:{
pointFormat:“{series.name}:{point.y}
”,
数值小数:1
}
};
}
})
结果。。。
您需要一个具有标志类型的附加系列,如示例中所示:是的,您已经厌倦了首先遵循该类型,但继续得到未标记的类型错误:在加载标志时无法读取未定义的属性“series”。您的series对象看起来如何,您尝试在哪个系列索引中实现数据?您也可以尝试调用函数。您已经在github上添加了指向上面完整代码的链接。在绘制图表之前,您可以使用addSeries函数吗?AddSeriers可以在图表初始化之后使用,但是正如我前面提到的,请检查为什么您的系列obejct被定义,因为您可能指的是不存在的系列。我想我现在已经解决了这个问题,JSON数据在添加标志之前还没有完成加载。因此,我改变了现在获取数据的方式,使用
$.ajax
调用now来获取数据,这意味着在添加标志之前,它将等待所有内容加载完毕。我已经更新了github上的所有代码以反映这一点。谢谢。
$.ajax({
url:"jsonloaddata.php?interval="+interval+"&location="+ name.toLowerCase()+"&querytype="+querytype.toLowerCase(),
dataType:'json',
async:false,
success:function(data) {
// do stuff.
console.log( "success with grabing json data for " + name.toLowerCase());
seriesOptions[i] = {
name: name + ' Temperature',
data: data,
color: colors[i],
id: 'dataseries',
type: 'line',
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
valueDecimals: 1
}
};
}
})