-2
링크에 자바 스크립트 변수를 추가하려면 어떻게해야합니까? 아래 코드는 빈 페이지를 생성합니다. viewData.php에는 PHP GET 변수가 포함되어 기간 및 유형을 가져와 대여 또는 판매 금액을 가져올 지 여부를 결정합니다. 기간은 yyyymm 형식입니다.자바 스크립트 변수 연결
$(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]
}]
});
}
Dan에게 더 많은 것을 주어야합니다. 'series.name'이란 무엇입니까? 'viewData.php'의 코드는 무엇이고'period'는 어떻게 처리됩니까? ... 그리고 그것은 링크가 아닙니다 ... –
위의 코드는 단일 문자열을 가진 배열을 만듭니다. 변수를 가지고 실제로 당신이하고있는 것을 보여줄 필요가 있습니다. JS에서 이름을 이스케이프 처리해야합니다. –
이것이 모두있는 코드라면 무엇을 기대합니까? – ComFreek