Javascript addpoint并不是在highcharts中添加点,在highcharts中,数据是通过ajax动态更新的
我的任务是动态添加多个系列并动态更新系列数据。 我的数据是通过ajax请求加载的 我使用了highcharts端给出的逻辑来动态更新数据。但是addpoint没有向序列添加点不知道为什么,当我检查序列对象时,它有数据,但dirtyfield设置为true(不知道原因) 下面给出的代码用于动态加载数据。这里的问题是添加点,而不是将数据添加到图形中。 series对象正在显示isDirty:true isDirtyData:对 我想这件事需要处理。请帮帮我。面对这个问题已经有相当长的一段时间了Javascript addpoint并不是在highcharts中添加点,在highcharts中,数据是通过ajax动态更新的,javascript,ajax,highcharts,highstock,Javascript,Ajax,Highcharts,Highstock,我的任务是动态添加多个系列并动态更新系列数据。 我的数据是通过ajax请求加载的 我使用了highcharts端给出的逻辑来动态更新数据。但是addpoint没有向序列添加点不知道为什么,当我检查序列对象时,它有数据,但dirtyfield设置为true(不知道原因) 下面给出的代码用于动态加载数据。这里的问题是添加点,而不是将数据添加到图形中。 series对象正在显示isDirty:true isDirtyData:对 我想这件事需要处理。请帮帮我。面对这个问题已经有相当长的一段时间了 fr
from_date=new Date().getTime()-60000;
function requestData ()
{
console.log("into request data")
console.log(TypeOfParameter,sub_type,sub_type_parameter,hostname,from_date)
$.ajax({
url:serverUrl+'/api/fetch_params/',
type:'GET',
data:{'type':TypeOfParameter,'sub-type':sub_type,'hostname':hostname,'param':sub_type_parameter,'from-date':from_date},
success:function(response)
{
console.log("into success")
var id=sub_type+sub_type_parameter
var series = chart.get(id)
shift = series.data.length > 150; // shift if the series is longer than 300 (drop oldest point)
console.log(shift)
response= $.parseJSON(response)
var x=sub_type;
all_data=response.response.data[x]
itemdata=[]//
console.log(all_data.length)
//console.log(new Date(all_data[all_data.length-1][0]),'latest timestamp')
from_date=all_data[all_data.length-1][0]
// series.addPoint(all_data,false,shift);
console.log("series name:",series.data.length,series.name)
for (var i = 0; i < all_data.length; i++)
{
console.log(all_data[i][0],all_data[i][1]);
series.addPoint({ x: all_data[i][0],y: all_data[i][1],id: i},false,shift);
}
console.log(series,"object")
console.log("hey",series.data.length)
console.log("hey",series.data.length )
console.log(series.data)
console.log("out of success")
//chart.redraw();
setTimeout(requestData, 60000);
},
cache:false,
error:function()
{
console.log("err")
}
});
console.log("out of request ")
}
这是动态添加axis的代码
$(function (
) {
console.log("into highcharts")
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'cpu Usage'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
id:sub_type+sub_type_parameter,
name: 'CPU',
data: []
}]
});;
console.log("out of highcharts")
});
chart = $('#container').highcharts();
var flag=true
if(TypeOfParameter=='cpu'&&flag)
{
console.log("entering into cpu",sub_type,flag)
// all_data = response.response.data[sub_type]
// itemdata=[]
// for(i in all_data)
// {
// itemdata.push(all_data[i][1])
// }
// console.log(itemdata[0])
// console.log("Drawing trend")
chart.addAxis({ // Primary yAxis
id:'Cpu_axis'+sub_type_parameter,
labels: {
formatter: function() {
return this.value;
},
style: {
color: '#89A54E'
}
},
title: {
text: "core "+ sub_type+ " "+sub_type_parameter,
style: {
color: '#89A54E'
}
},
lineWidth: 1,
lineColor: '#08F'
});
chart.addSeries({
id:sub_type+sub_type_parameter,
name: "core "+sub_type+" "+sub_type_parameter,
data:[],
tooltip: {
valueSuffix: ' q %'
},
yAxis:'Cpu_axis'+sub_type_parameter
})
//chart.redraw();
flag=false
console.log("returning from cpu")
}
这是关于如何使用
addPoint()
函数的:
series.addPoint({ x: all_data[i][0],y: all_data[i][1],id: i},false,shift);
您已将redraw设置为false,因此它不会重新绘制图表。将其设置为true,则会起作用
更多信息:我可以看出这是2013年的老问题。但我想告诉其他正在寻找这个问题答案的人 有一个highcharts.js错误。简而言之,错误描述是:当使用addPoint()方法将点添加到图表系列中时,这个新点不会出现在someSerie.data数组中 我建议对此问题采取以下解决方法“someSerie.data数组中不存在新点”: 在进行以下检查之后:
if(series.data.length) {
chart.redraw();
}
应该可以工作。嘿,我故意将其设置为false,将其设置为true挂起我的浏览器,我发现原因是没有数据要重画,它一直在调用它。我在每次ajax请求后检查数据,它是空列表。请帮忙。好的,那你为什么禁用了redraw()?此处:
//chart.redraw()代码>我可以“实时”查看它吗?嗨,我已禁用检查数据是否添加到图表中,如果我启用它,浏览器将被挂起。这是我的全部代码。我在这个问题上纠缠了很长时间。请帮忙,这很紧急。我无法找出series.addpont()无法工作的原因。将此代码放入无法工作的JSFIDLE中是没有帮助的。。我是指现场或类似的东西。我不能把现场链接,因为我在本地主机工作。目前本地包含的文件很少。你能告诉我加点不加点的原因吗。我见过series对象,它已处理扩展数据和ydata。但数据[]字段中没有任何内容。还设置了isDirt:true和isDirtydata:true,而在其他系列中,这两个字段设置为false。什么是isDirty字段的原因。我是否需要检查我的逻辑,或者我对highchart的东西有什么问题?你找到解决方案了吗?我也有同样的问题,有时会增加分数,但大多数时候会出现空白蜡烛。
if(series.data.length) {
chart.redraw();
}