Jgplot - 以某种方式绘制了以前的数组数据? [英] Jgplot - somehow previous array data being plotted?

查看:66
本文介绍了Jgplot - 以某种方式绘制了以前的数组数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以这是我第一次真正进入Javascript,而且这里或那里有一个奇怪的部分,因为我们正在处理一个用于DCS的HMI。但是,我不相信我所拥有的问题与此有任何关系,我想不知何故我只是搞砸了javascript,这让我很头疼。



我有一些代码从DCS读入数组标签变量数据,以便在HMI的屏幕上为操作员绘制该数组数据。一切似乎工作得很好,除了这里有几个非常特殊的东西。当我第一次加载页面时,脚本运行(我已经使用警报确认代码正在处理),但是图表没有显示。当我选择不同的配置文件时,脚本会再次运行并且绘图会加载,但显示的数组数据是针对上一个绘图 - 这没有任何意义,因为必须覆盖该数组数据(据我所知)和title变量显示正确/新数据,这也确认它应该读入数组的标记变量也是正确的。因此,即使代码第二次运行,它似乎只是显示前一个绘图而不是使用新的绘图数据加载新绘图。以下是有问题的代码:



 function buildProfile(titleText){

alert(buildProfile Script正在运行,titleText变量作为+ titleText传递;

var profileSeries = [],
profileArr = [],
count = 0,
size = 840;

while(count< size){
profileArr [count] = ProfileData.DataValue(CmNameProfile.PROFILEA.DATAARRAY [+ count +]);
count ++;
if(count< 1){
alert(While Loop Started);
};
if(count> 839){
alert(While Loop Finished);
};
};

alert(While Loop Complete?如果是这样,这个值应该在所选配置文件的适当范围内。值为+ profileArr [50]);

profileSeries.push(profileArr);

var optionsObj = {
title:titleText,
axes:{xaxis:{min:0,max:840}},
seriesDefaults:{color:' #00ff00',lineWidth:2,showMarker:false},
grid:{background:'#000000',gridLineColor:'#aaaaaa',shadow:false},
canvasOverlay:{show:true,对象:[{horizo​​ntalLine:{name:'setpoint',y:15,lineWidth:2,color:'#ffffff',shadow:false}}]}
};

plot1 = $ .jqplot('plotDiv',profileSeries,optionsObj).replot();

}





我的尝试:



好​​的,所以我更新了上面的代码。因此,在初始页面加载时,while脚本未运行。但是,如果我第二次调用脚本,它就会这样做。这就是为什么没有显示配置文件,数组中没有数据的原因。为什么while循环不会运行?!

解决方案

.jqplot('plotDiv',profileSeries,optionsObj).replot();

}





我的尝试:



好​​的,所以我更新了上面的代码。因此,在初始页面加载时,while脚本未运行。但是,如果我第二次调用脚本,它就会这样做。这就是为什么没有显示配置文件,数组中没有数据的原因。为什么while循环不会运行?!?


好的,所以我最终在我的函数上设置了1秒的延迟,它似乎在页面加载和现在的每个后续调用上都完美地执行。我认为这将满足我的需求,我几乎没有时间在这个项目上,所以现在必须这样做。 :)

Ok, so this is my first forray into Javascript really, and there's an odd piece here or there because we're dealing with an HMI for a DCS. But, I don't believe the issue I'm having has anything to do with that, I think somehow I'm just screwing something up with the javascript and it's causes me a big headache here.

I have some code that reads into an array tag variable data from the DCS in order to plot that array data on the screen in the HMI for the operator. Everything seems to be working fine except for a couple really peculiar things here. When I first load the page, the script runs (I've used alerts to confirm the code is processing), but the plot does not show up. When I select a different profile, the script runs again and the plot loads, but the array data that shows is for the previous plot - which makes no sense because that array data must be get overwritten (as far as I understand this) and the title variable is showing the correct/new data which also confirms that the tag variables that it should be reading into the array are correct as well. So it seems as though even though the code is being run a second time, it's somehow just showing the previous plot instead of loading the new plot with the new plot data. Here is the code in question:

function buildProfile(titleText){

	alert("buildProfile Script is running, titleText variable was passed as " + titleText);

	var profileSeries = [],
		profileArr = [],
		count = 0,
		size = 840;

	while (count < size){
		profileArr[count] = ProfileData.DataValue("CmNameProfile.PROFILEA.DATAARRAY[" + count + "]");
		count++;
		if (count < 1){
			alert("While Loop Started");
			};
		if (count > 839){
			alert("While Loop Finished");
			};
		};

	alert("While Loop Complete? If so this value should be in the proper range for profile selected. The value is " + profileArr[50]);

	profileSeries.push(profileArr);
	
	var optionsObj = {
		title:titleText,
		axes:{xaxis:{min:0, max:840}},
		seriesDefaults:{color:'#00ff00', lineWidth:2, showMarker:false},
		grid:{background:'#000000', gridLineColor:'#aaaaaa', shadow:false},
		canvasOverlay:{show:true, objects:[{horizontalLine:{name:'setpoint', y:15, lineWidth:2, color:'#ffffff', shadow:false}}]}
	};

	plot1 = $.jqplot('plotDiv', profileSeries, optionsObj).replot();

}



What I have tried:

Ok, so I've updated the code above. So, on the initial page load, the while script is NOT running. But then it does if I call the script a second time. So that must be why the profile is not being displayed, no data in the array. Why would the while loop not run?!?

解决方案

.jqplot('plotDiv', profileSeries, optionsObj).replot(); }



What I have tried:

Ok, so I've updated the code above. So, on the initial page load, the while script is NOT running. But then it does if I call the script a second time. So that must be why the profile is not being displayed, no data in the array. Why would the while loop not run?!?


Ok, so I wound up setting a 1 second delay on my function and it seems to be executing perfectly on page load and every subsequent call now. I think this is going to meet my needs and I'm almost out of hours on this project so this will have to do for now. :)


这篇关于Jgplot - 以某种方式绘制了以前的数组数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆