2015-12-29 296 views
1

我使用AmCharts製作了一段時間內的付款圖表。未捕獲TypeError:無法讀取屬性'mouseX'的未定義

我的AmCharts配置看起來正確。

另請注意我不是Javascript的專家。

使用AmCharts 3.18.3.free

完整的控制檯輸出

Uncaught TypeError: Cannot read property 'mouseX' of undefined @ amcharts.js:4107
d.ChartCursor.d.Class.update @ amcharts.js:4107
e.AmRectangularChart.e.Class.update @ serial.js:346
e.AmSerialChart.e.Class.update @ serial.js:980
d.update @ amcharts.js:196

我還使用RainbowVis-JS

newdata = [{"date":"2015-12-01T00:00:00-0600","Company 1":145,"Company 2":124},{"date":"2015-11-01T00:00:00-0600","Company 1":165,"Company 2":136}]; 

此整個項目坐落在一個被稱爲與jquery

用戶選擇一個公司並且點擊按鈕,這觸發關閉此和提取數據的功能。

該片段位於正在運行的函數的主體中。 (mainFunc)

var that = this; 
this.chart = new AmCharts.AmSerialChart(); 

以下是在主函數下的顯示功能(mainFunc - > displayFunc)

newdata.reverse() 
var companiesLength = companies.length; 
var rainbow = new Rainbow(); 
rainbow.setSpectrum('red', 'blue', 'green', 'yellow'); 
rainbow.setNumberRange(1, companiesLength); 
rainbow.colourAt(i); 
var side = 'left' 
var companiesLength = companies.length; 
for (var i = 0; i < companiesLength; i++) { 
    var valueAxis = new AmCharts.ValueAxis(); 
    valueAxis.gridAlpha = 0; 
    valueAxis.axisThickness = 2; 
    valueAxis.axisAlpha = 1; 
    valueAxis.position = side; 
    valueAxis.axisColor = rainbow.colourAt(i); // yields a specific html color 
    that.chart.addValueAxis(valueAxis); 

    var graph = new AmCharts.AmGraph(); 
    //graph.type = "serial"; 
    graph.bullet = "round"; 
    graph.fillAlphas = 0; 
    graph.bulletBorderThickness = 1; 
    graph.hideBulletsCount = 30; 
    graph.valueField = companies[i]; // yields the name of the company 
    graph.title = companies[i]; 
    graph.lineColor = rainbow.colourAt(i); 
    that.chart.addGraph(graph); 

    side = (side == 'left' ? 'right' : 'left'); 
} 
that.chart.theme = "chalk"; 
that.chart.marginRight = 20; 
that.chart.marginLeft = 20; 
that.chart.autoMargins = false; 
that.chart.dataProvider = newdata; 
that.chart.categoryField = "date"; 
that.chart.dataDateFormat = "YYYY-MM-DDTHH:NN:SS-0600"; 
that.chart.export = {"enabled": true, "position": "bottom-right"}; 

var categoryAxis = that.chart.categoryAxis; 
categoryAxis.parseDates = true; 
categoryAxis.minPeriod = "MM"; 
categoryAxis.minorGridEnabled = true; 
categoryAxis.minorGridAlpha = 0.15; 
categoryAxis.axisColor = "#DADADA"; 

var chartCursor = new AmCharts.ChartCursor(); 
chartCursor.cursorPosition = "mouse"; 
that.chart.addChartCursor(chartCursor); 

legend = new AmCharts.AmLegend(); 
legend.useGraphSettings = "center"; 
that.chart.addLegend(legend); 
that.chart.addListener("dataUpdated", that.chart.zoomOut); 
that.chart.write("chartdiv"); 
that.chart.zoomOut(); 

serial.js:346

this.chartCursor && this.chartCursor.update && this.chartCursor.update() 

serial.js: 980

e.AmSerialChart.base.update.call(this); 

amcharts .js文件:196

c; c--) a[c].update && a[c].update(), b && (a[c].autoResize ? a[c].validateSize && a[c].validateSize() : a[c].premeasure && a[c].premeasure()); 

我想補充一點,我曾在這個從尋找到AmCharts代碼,試圖回溯它爲什麼失敗,無法找出原因。

這裏是它的抱怨,中間線特別

var a = this.chart, 
    b = a.mouseX - this.x, 
    c = a.mouseY - this.y; 
+0

我加載串行和amcharts以正確的順序。 – StoneyD

+0

我注意到圖表中存在一些違規行爲:1)您可以將'categoryField'設置爲「month」,而數據具有「date」。 2)數據點反轉(降序),應按升序排列。 (如果你不能對你的源數據重新排序,你可以使用'newdata.reverse()',讓我知道是否修正上述兩個問題有助於解決這個問題 – martynasma

+0

注意到另一個問題:你有'graph.type =「serial」'。沒有這樣的圖表打印錯誤,這是令人困惑的圖表。對於默認的折線圖類型,完全刪除此行。 – martynasma

回答

2

所以我要回答我的問題的具體代碼段。 @martynasma幫助我們理解代碼無法正常工作的原因非常有幫助。

錯誤代碼:

<div class='chartdiv' >&nbsp;</div> 

更正代碼:

<div class='chartdiv' id='chartdiv'>&nbsp;</div> 
相關問題