【发布时间】:2017-07-26 06:49:56
【问题描述】:
我有一个类似的问题,就像在highchart chart redraw method is not refreshing the chart 上发布的一样,但我正在使用极坐标图,所以那里给出的解决方案不能解决我的问题。
所以,下面的代码正确显示了高图,但没有刷新数据。现在我正在寻求建议/帮助如何解决它。
$(function() {
$.getJSON('wind_graph.php?callback=?', function(dataWind) {
var direction = Wind_direction;
var polarOptions = {
chart: {
polar: true,
events : {
load : function () {
setInterval(function(){
RefreshDataWind();
}, 1000);
}
}
},
title: {
text: 'Wind Direction'
},
pane: {
startAngle: 0,
},
tooltip: {
enabled: false
},
legend: {
enabled: false
},
// the value axis
xAxis: {
tickInterval: 15,
min: 0,
max: 360,
labels: {
formatter: function() {
return this.value + '°';
}
}
},
plotOptions: {
series: {
pointStart: 0,
pointInterval: 30,
marker: {
enabled: false
},
},
}
};
// The polar chart
$('#graph-1').highcharts(Highcharts.merge(polarOptions, {
yAxis: {
tickInterval: 5,
min: 0,
max: 25,
visible: false
},
credits: {
enabled: false
},
series: [{
type: 'line',
name: 'Direction',
data: [
[0, 0],
[direction, 20]
],
lineColor: '#7cb5ec',
enableMouseTracking: false,
visible: true,
lineWidth: 2,
zIndex: 8,
}
]
}));
function RefreshDataWind()
{
var chart = $('#graph-1').highcharts();
$.getJSON('wind_graph.php?callback=?', function(dataWind)
{
var direction = Wind_direction;
chart.redraw();
});
chart.redraw();
}
});
});
更准确地说:如果给定的 Wind_direction 值等于 0(零),那么我需要在图表上显示以下“样条线”:
{
type: 'spline',
name: 'CentralCicrleCalmWind1',
data: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
pointInterval: 30,
pointStart: 0,
lineColor: windLineColor,
enableMouseTracking: false,
lineWidth: windLineWidth,
visible: showCentralCicrleCalmWind,
}, {
type: 'spline',
name: 'CentralCicrleCalmWind2',
data: [2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5],
pointInterval: 30,
pointStart: 0,
lineColor: windLineColor,
enableMouseTracking: false,
lineWidth: windLineWidth,
visible: showCentralCicrleCalmWind,
}
如您所见,我将“showCentralCircleCalmWind”等附加参数设置为 TRUE 或 FALSE,这取决于我在代码顶部准备的给定“Wind_direction”值和逻辑(此处未粘贴)。 我需要的是:
- 读取给定 JSON 中变量的值
- 在javascript代码的开头设置变量“direction”
- 使用 higcharts 库显示图表
- 从 JSON 中读取新值
- 将变量“direction”更改为新值。
- 显示给定值的新图表
- 回到第 4 点...
【问题讨论】:
-
最后一个
chart.redraw();似乎没有必要。去掉它 。你的浏览器控制台有什么错误吗? -
我在浏览器控制台中没有任何错误。只有关于长时间运行的 JavaScirpt 任务的违规警告需要 369 毫秒。也许我应该改变jquery版本?实际上我使用的是 jquery 1.11.3
-
更换最新的并检查。还有为什么要花这么多时间?
-
更改为 3.1.1.min 并且 Violation 错误不再显示,但刷新仍然无效。
标签: javascript jquery charts highcharts data-visualization