我正在最终确定我的网络应用程序,并开始测试不同浏览器的最新版本。
不幸的是,Internet Explorer(9)似乎有一些问题(再次!-.-),只有一行非常简单的代码。
我正在使用由amCharts lib设计的图表 - 并且已经实现了一个小函数来刷新它:
function validateData()
{
chart.validateData();
console.log("Data validated");
}
现在,IE9不是仅执行amCharts函数" validateData()"而是抛出错误:
SCRIPT5007: Unable to get value of the property "validateData": object is null or undefined
我发现这个错误特别令人不安,因为它说的是“获得价值”#34;和"财产"。 validateData是一个函数(没有任何返回值)不是某些类型的属性,当然它没有价值...
IE试图在这做什么?!为什么它不像其他浏览器一样执行代码行......
我很感激你们能提供的任何帮助。
如果需要更详细的背景信息,我将在下面提供更多代码段:
HTML头:
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<!-- Suggested fix in another SO thread. Doesn't work! -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<script src="amcharts/amcharts.js" type="text/javascript"></script>
<script src="amcharts/serial.js" type="text/javascript"></script>
<script type="text/javascript" src="js/siteScript.js"></script>
<script type="text/javascript" src="amcharts/exporting/rgbcolor.js"></script>
<script type="text/javascript" src="js/moment.min.js"></script>
<script type="text/javascript" src="js/sharepointplus-3.0.8.js"></script>
<script type="text/javascript" src="js/TableSort.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="img/chart_release.png" rel="shortcut icon" type="image/x-icon" />
<script type="text/javascript">
// 650 lines of JS functions
//
// Loads and transforms XML data in various ways
//
// Manipulates XML data in a way that allows a graphic representation of said data
// Eventually fills the chartData[] array of amChart library, to provide the datasets behind the chart
</script>
HTML正文:
<!-- Various HTML code to render the page before this point -->
<script type="text/javascript">
var chart;
var chartData = [];
var chartCursor;
AmCharts.ready(function() {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "amcharts/images/";
chart.dataProvider = chartData;
chart.categoryField = "date";
chart.dataDateFormat = "MM/DD/YYYY";
chart.baseHref = true;
// listen for "dataUpdated" event (fired when chart is rendered) and call zoomChart method when it happens
chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
categoryAxis.dashLength = 1;
categoryAxis.gridAlpha = 0.15;
categoryAxis.minorGridEnabled = true;
categoryAxis.axisColor = "#DADADA";
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0.2;
valueAxis.dashLength = 1;
chart.addValueAxis(valueAxis);
// GRAPH
var graph = new AmCharts.AmGraph();
graph.title = "red line";
graph.valueField = "visits";
graph.bullet = "round";
graph.bulletBorderColor = "#FFFFFF";
graph.bulletBorderThickness = 2;
graph.bulletBorderAlpha = 1;
graph.lineThickness = 2;
graph.lineColor = "#0db503";
graph.negativeLineColor = "#b5030d";
graph.balloonText = "[[category]]<br><b><span style='font-size:14px;'>value: [[value]]</span></b>";
graph.hideBulletsCount = 50; // this makes the chart to hide bullets when there are more than 50 series in selection
chart.addGraph(graph);
// CURSOR
chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorPosition = "mouse";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chartScrollbar.graph = graph;
chartScrollbar.scrollbarHeight = 40;
chartScrollbar.color = "#FFFFFF";
chartScrollbar.autoGridCount = true;
chart.addChartScrollbar(chartScrollbar);
// Click event
chart.addListener("clickGraphItem", function (event) {
getDetails(event.item.category);
});
// WRITE
chart.write("charts_container");
});
function zoomChart() {
chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
}
function setPanSelect() {
if (document.getElementById("rb1").checked) {
chartCursor.pan = false;
chartCursor.zoomable = true;
} else {
chartCursor.pan = true;
}
chart.validateNow();
}
// Function that produces the error in IE9
function validateData()
{
chart.validateData();
console.log("Data validated");
}
</script>
修改
根据要求,这是一个调用validateData()函数的片段。它位于HTML head
中的JS块中// Before this is called there are several data transformation/manipulations
// and other stuff regarding editing the source data from a XML file
if (filled == true)
{
for (k=0;k<arrDate.length;k++)
{
var dataObject = {
date: arrDate[k],
result: arrResult[k],
};
chartData.push(dataObject);
validateData();
}
}