我對highcharts一個.js代碼:Highcharts沒有表現出一系列的數據與javascript函數
$(function loadTransactionsLevel() {
//Auto call function, for 1 minute
setInterval(loadTransactionsLevel, 60000);
var nowDate = new Date();
var nowYear = nowDate.getFullYear();
var nowMonth = (nowDate.getMonth()+1);
var nowDay = nowDate.getDate();
var nowHour = nowDate.getHours();
var nowMinus10Minutes = (nowDate.getMinutes() - 10);
var nowMinutes = (nowDate.getMinutes() - 1);
Highcharts.setOptions({
lang: {
loading: 'Cargando...',
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
weekdays: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
shortMonths: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
exportButtonTitle: "Exportar",
printButtonTitle: "Importar",
rangeSelectorFrom: "Desde",
rangeSelectorTo: "Hasta",
rangeSelectorZoom: "Período",
downloadPNG: 'Descargar imagen PNG',
downloadJPEG: 'Descargar imagen JPEG',
downloadPDF: 'Descargar imagen PDF',
downloadSVG: 'Descargar imagen SVG',
printChart: 'Imprimir',
resetZoom: 'Reiniciar zoom',
resetZoomTitle: 'Reiniciar zoom',
thousandsSep: ",",
decimalPoint: '.'
}
});
$('#liveTransactionsLevel').highcharts({
chart: {
type: 'column',
backgroundColor: '#333333'
},
title: {
text: 'Traffic Level3',
style: {
color: '#dedede'
}
},
subtitle: {
text: 'Messages passed',
style: {
color: '#dedede'
}
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%A %d de %B de %Y', (new Date(nowYear + '-' + nowMonth + '-' + nowDay)), false) + ': ' +
'<b>' + Highcharts.numberFormat(this.y, 0) + '</b>';
}
},
legend: {
enabled: false
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[2]],
[1, Highcharts.Color(Highcharts.getOptions().colors[2]).setOpacity(0).get('rgba')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
},
series: {
animation: false
}
},
xAxis: {
title: {
text: Highcharts.dateFormat('%A %d de %B de %Y', (new Date(nowYear + '-' + nowMonth + '-' + nowDay)), false),
style: {
color: '#AAAAAA'
}
},
labels: {
style: {
color: '#dedede'
}
},
type: 'datetime',
min: Date.parse(nowYear + "-" + nowMonth + "-" + nowDay + " " + nowHour + ":" + nowMinus10Minutes + " UTC"),//Date.UTC(nowYear, nowMonth, nowDay, nowHour, nowMinus10Minutes),
max: Date.parse(nowYear + "-" + nowMonth + "-" + nowDay + " " + nowHour + ":" + nowMinutes + " UTC"),//Date.UTC(nowYear, nowMonth, nowDay, nowHour, nowMinutes),
showEmpty: true,
tickInterval: 1000 * 60, // one minute
tickPixelInterval: 10
},
yAxis: {
title: {
text: 'Success',
style: {
color: '#dedede'
}
},
labels: {
style: {
color: '#dedede'
}
},
allowDecimals: false,
min: 0,
max: null,
showEmpty: true
},
series: [{
type: 'column',
color: '#5DC05D',
lineWidth: 2,
name: 'Messages passed',
data: getData()
}]
});
});
function getData() {
var array_keys = [];
var array_values = [];
var data = [];
$.ajax({
type: "GET",
url: "http://localhost:8080/flkLive/ws/root/success",
data: "",
success: function(values){
for (var key in values) {
if (values.hasOwnProperty(key)) {
array_keys.push(key);
array_values.push(values[key]);
}
}
array_keys.sort();
array_values.sort();
for (var i = 0; i < array_keys.length; i++){
data[i] = [
[ Date.parse(array_keys[i] + " UTC"), array_values[i] ]
]
}
alert(data);
return data;
}
});
}
但是當我運行該項目,highcharts沒有顯示任何數據,有什麼不對?
下面是一個值的圖像格式顯示(time_in_milliseconds,int_value):
與Java無關。 – chrylis
mmmmm wel ... well ... –
你應該爲你的yValue數字,而不是字符串。嘗試使用parseFloat(array_values [i])http://www.w3schools.com/jsref/jsref_parsefloat.asp –