-2
如何在鏈接中添加一個JavaScript變量?下面的代碼產生一個空白頁。 viewData.php將包含PHP GET變量來獲取期間和類型,以確定我是否提取租金或銷售額。該時期將採用yyyymm格式。鏈接一個JavaScript變量
$(document).ready(function(){
init();
});
function init(){
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
urls = ['http:/testServer/testPage/viewData.php?period=' + series.name + ''];
$.ajax({
url: 'readData.php'
}).done(function(data) {
ar = data.split('###');
for(var i=0;i<ar.length;i++){
ar[i] = ar[i].split('##');
}
for(var i=0;i<ar[0].length;i++){
text = ar[0][i].split(' ').join('');
year = text.substring(0,4);
month = parseInt(text.split(year).join(''));
month = months[month-1];
ar[0][i] = month +','+year;
ar[1][i] = parseFloat(ar[1][i]);
ar[2][i] = parseFloat(ar[2][i]);
}
count = 0;
dates = [];
dates.push(ar[0][0]);
for(var i=1;i<ar[0].length;i++){
count++;
dates.push(ar[0][i]);
}
dates[dates.length-1] = ar[0][dates.length-1];
createGraph(ar,dates);
});
}
function createGraph(ar,dates){
$('#60MonthAmount').highcharts({
chart: {
type: "line"
},
title: {
text: '60 Month Revenue by Location Chart'
},
subtitle: {
text: ''
},
xAxis: {
title: {
text: 'Time Period'
},
labels: {
formatter: function() {
return this.value; // clean, unformatted number for year
}
},
categories: dates,
minTickInterval: 6,
showLastLabel: true,
},
yAxis: {
title: {
text: ''
},
min: 0,
labels: {
formatter: function() {
return this.value/1000000 +' mil';
}
}
},
tooltip: {
pointFormat: '{series.name} produced <b>${point.y:,.0f}</b><br/><p style="visibility: hidden;">_</p>'
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function() {
if(this.x>urls.length){
url = urls[0];
}else{
url = urls[this.x];
}
window.open(url, '_blank');
}
}
}
}
},
series: [{
name: 'Rentals',
data: ar[1]
}, {
name: 'Sales',
data: ar[2]
}]
});
}
要去給我們更多的丹。什麼是'series.name'? 'viewData.php'上的代碼是什麼,'period'是如何處理的? ...這不是一個鏈接... –
上面創建一個數組,其中包含一個單一的字符串;你需要顯示你實際上在做什麼*變量。你還需要JS-逃避這個名字。 –
如果這是你所有的代碼,你期望它做什麼? – ComFreek