gpt4 book ai didi

javascript - Highcharts Spline 未绘制前 30 个点的图形线。

转载 作者:行者123 更新时间:2023-11-28 09:08:19 25 4
gpt4 key购买 nike

我有一个效果很好的 highcharts 样条图。我改变了一些 ajax 调用,现在它不会绘制连接前 30 个左右点的线。它只是绘制点一段时间,然后线条就出现了。我更关心线条而不是点。

有谁知道为什么会这样吗?请参阅下面我的代码。预先感谢您的任何帮助!

var results_a;
var results_b;
var flag_a = 1;
var flag_b = 1;
var current_a;
var current_b;
var previous_a = 0;
var previous_b = 0;
var xmlhttp_a;
var xmlhttp_b;
var url_a = "http://mysite.com/web/johnsNumber.txt";
var url_b = "http://mysite.com/web/johnsNumber.txt";
////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadFirstDoc(url_a,cfunc)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp_a=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp_a=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp_a.onreadystatechange=cfunc;
xmlhttp_a.open("GET",url_a,true);
xmlhttp_a.send();
}

function myFunction_a()
{
loadFirstDoc(url_a,function()
{
if (xmlhttp_a.readyState==4 && xmlhttp_a.status==200)
{
current_a = parseInt(xmlhttp_a.responseText);
flag_a = 1;
}
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadSecondDoc(url_b,cfunc)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp_b=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp_b=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp_b.onreadystatechange=cfunc;
xmlhttp_b.open("GET",url_b,true);
xmlhttp_b.send();
}

function myFunction_b()
{
loadSecondDoc(url_b,function()
{
if (xmlhttp_b.readyState==4 && xmlhttp_b.status==200)
{
current_b = parseInt(xmlhttp_b.responseText);
flag_b = 1;
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

function randInRange(start, end){
return Math.floor(Math.random() * (end-start+1) + start);
}

function is_numeric(input){
return !isNaN(input);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////
/*js for first graph....container*/
$(function () {
$(document).ready(function() {
// Apply the grey theme
Highcharts.setOptions({
colors: ["#B00000"],

});

Highcharts.setOptions({
global: {
useUTC: false
}
});

var chart;
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {

// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {

myFunction_a(); //ajax call

//check if flag has been set...if so, then random number
if(flag_a == 1){
results_a = current_b;
; //results_a = randInRange(1, 5);
}
//flag not set so results = 0
else{
results_a = 0;
}
//Need to write to a text file right here
var x = (new Date()).getTime(), // current time
y = results_a;
series.addPoint([x, y], true, true);
//series.addPoint([x, y], true, true);
previous_a = current_a;
flag_a = 0;
}, 1500);
}
}
},
title: {
text: 'Linux Server Sales Graph',
style: {
color: '#B00000',
font: 'bold 20px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
}
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
min: -1,
max: 6,
title: {
text: 'Sales'
},
plotLines: [{
value: 0,
width: 1,
color: '#000',
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'sales/sec',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;

for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: randInRange(1, 5)
});
}
return data;
})()
}]
});
});

});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*script for the second graph...container2*/
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
colors: ["#0000FF"],
});
Highcharts.setOptions({
global: {
useUTC: false
}
});

var chart;
$('#container2').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {

// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
myFunction_b();
if(flag_b == 1){
results_b = current_b;
//results_b = randInRange(1, 5);
}
else{
results_b = 0;
}
//need to write to text file right here
var x = (new Date()).getTime(), // current time
y = results_b;
//series.addPoint([x, y], true, true);
series.addPoint([x, y], true, true);
previous_b = current_b;
flag_b = 0;
}, 1500);
}
}
},
title: {
text: 'Windows Server Sales Graph',
style: {
color: '#0000FF',
font: 'bold 20px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif'
}
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
min: -1,
max: 6,
title: {
text: 'Sales'
},
plotLines: [{
value: 0,
width: 1,
color: '#000',
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'sales/sec',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;

for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: randInRange(1, 5)
});
}
return data;
})()
}]
});
});

});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

最佳答案

1)在第一个图表中:

 if(flag_a == 1){
results_a = current_b;
//results_a = randInRange(1, 5);
}

不应该存在current_a吗?

2)我创建了简单的图表:http://jsfiddle.net/3bQne/102/与你的选择。唯一的区别是值始终相同。正如您所看到的,它工作得很好。

3) 控制台有什么错误吗?尝试更新我的示例以重现问题。

关于javascript - Highcharts Spline 未绘制前 30 个点的图形线。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16597052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com