需要一些关于此错误的帮助:
Uncaught Rickshaw.Graph needs a reference to an element
rickshaw.min.js:1 initialize
rickshaw.min.js:1 Rickshaw.Graph
rickshaw.min.js:1 loadChart
chart.js:23 (anonymous function)
stockDisplay.html:21 window.DoorLock.DoorLock._tryToFreeWaitList
onsenui.js:4123 window.DoorLock.DoorLock._unlock
onsenui.js:4118 unlock
onsenui.js:4100 (anonymous function)
这是JS功能:
function loadChart(){
var stockDataSeries = (function () {
var stockDataSeries = null;
$.ajax({
'async': false,
'global': false,
'url': 'http://[host_name]/json/aa_historicalData.json',
'dataType': "json",
'success': function (data) {
stockDataSeries = JSON.stringify(data);
},
'error': function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
return stockDataSeries;
})();
var stockChart = new Rickshaw.Graph({
element: document.querySelector('chart'),
renderer: 'line',
width: '345',
series: [ {
color: 'steelblue',
name: 'Price',
data: stockDataSeries
} ]
});
var x_axis = new Rickshaw.Graph.Axis.X( {
graph: stockChart
} );
var y_axis = new Rickshaw.Graph.Axis.Y( {
graph: stockChart,
orientation: 'left',
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
element: document.getElementById('y_axis')
} );
var detail = new Rickshaw.Graph.HoverDetail({
graph: stockChart
});
graph.render();
}
答案 0 :(得分:1)
而不是使用document.querySelector('chart')
尝试使用document.getElementById('chart')
。我相信你的错误是由querySelector返回而没有元素。