我正在尝试使用Flot库生成图形。
var d= [ [1293840000000,332],[1293926400000,321],[1294012800000,310],[1294099200000,299],[1294185600000,288],[1294272000000,277],[1294358400000,266],[1294444800000,255],[1294531200000,244],[1294617600000,233],[1294704000000,222],[1294790400000,211],[1294876800000,200],[1294963200000,189],[1295049600000,178],[1295136000000,167],[1295222400000,156],[1295308800000,145],[1295395200000,134],[1295481600000,123],[1295568000000,112],[1295654400000,101],[1295740800000,90],[1295827200000,79],[1295913600000,68],[1296000000000,57],[1296086400000,46],[1296172800000,35],[1296259200000,24],[1296345600000,13]];
$.plot($("#placeholder"), [d], { xaxis: { mode: "time" } });
上述代码生成了图表。但是当我将包含在变量
d[]
中的数据尝试使用时...var d=[formateddata3];
当 formatteddata3 包含
[1293840000000,332],[1293926400000,321],[1294012800000,310],[1294099200000,299],
[1294185600000,288],[1294272000000,277],[1294358400000,266],[1294444800000,255],
[1294531200000,244],[1294617600000,233],[1294704000000,222],[1294790400000,211],
[1294876800000,200],[1294963200000,189],[1295049600000,178],[1295136000000,167],
[1295222400000,156],[1295308800000,145],[1295395200000,134],[1295481600000,123],
[1295568000000,112],[1295654400000,101],[1295740800000,90],[1295827200000,79],
[1295913600000,68],[1296000000000,57],[1296086400000,46],[1296172800000,35],
[1296259200000,24],[1296345600000,13]
我在考虑的问题是将变量的值传递到数组中。我正在使用for循环构建formateddata3
。希望有人能帮我找到正确的方法。
另外,当我用没有传递变量的值来警示d时,我得到了:
1293840000000,332,1293926400000,321,1294012800000,310,1294099200000,299,
1294185600000,288
如果我使用传递的变量时进行警报,则会得到以下结果:
[1293840000000,332],[1293926400000,310],[1294012800000,288]
第一个函数生成图表...
//以下是完整的代码
var d1=[{!formateddata1}];
var d2=[{!formateddata2}];
var start = new Date(document.getElementById('Stardate').value);
var end= new Date(document.getElementById('CompleteDate').value);
var noofdays=datediff(start ,end,'days') ;
var hours= document.getElementById('page1:form2:amount').value ;
var totalhours= {!est_project_hours};
var formateddata3='';
var cumhours=0;
for (var i=0;i<noofdays;i++)
{
if (i==0)
{
cumhours=totalhours;
formateddata3='['+start.getTime()+ ','+cumhours+'],[';
alert(formateddata3);
}
else if(i==noofdays-1)
{
start.setDate(start.getDate()+1);
cumhours=cumhours-hours;
formateddata3=formateddata3+start.getTime()+ ','+cumhours+']';
}
else
{
start.setDate(start.getDate()+1);
cumhours=cumhours-hours;
formateddata3=formateddata3+start.getTime()+ ','+cumhours+'],['
}
}
// when i use the d3 with these values the graph works
//var d3=[ [1293840000000,332],[1293926400000,321],[1294012800000,310], [1294099200000,299],[1294185600000,288],[1294272000000,277],[1294358400000,266],[1294444800000,255],[1294531200000,244],[1294617600000,233],[1294704000000,222],[1294790400000,211],[1294876800000,200],[1294963200000,189],[1295049600000,178],[1295136000000,167],[1295222400000,156],[1295308800000,145],[1295395200000,134],[1295481600000,123],[1295568000000,112],[1295654400000,101],[1295740800000,90],[1295827200000,79],[1295913600000,68],[1296000000000,57],[1296086400000,46],[1296172800000,35],[1296259200000,24],[1296345600000,13]];
//alert([formateddata3]);
var d3=[];
var d3=[formateddata3];// but when i use it like this it doesnt work
alert('d3 value is '+d3);
alert('d1 value is '+d1);
alert('d2 value is '+d2);
j$.plot(j$("#placeholder"),[ { label: "Timelog", data:d1 },{ label: "Avg", data:d2 },{ label: "Simulated", data:d3}],
{
series: {
lines: { show: true },
points: { show: true }
},
xaxis:
{ mode: "time",
min: {!startdate},
max: {!enddate}
}
,yaxis: {
min:0, tickSize: 5
}
});