JavaScript运行时错误:Object expected

JavaScript runtime error: Object expected

本文关键字:expected Object 运行时错误 JavaScript      更新时间:2023-09-26

我正在尝试复制HighChart图形。它在JsFiddle上工作得很好。但在我的本地web应用程序,它抛出错误:

JavaScript运行时错误:Object expected

highcharts.src.js文件中的代码段出现错误

/ Set up auto resize
        if (optionsChart.reflow !== false) {
            addEvent(chart, 'load', function () {
                chart.initReflow();
            });
        }

this I my JSFiddle

http://jsfiddle.net/u9xES/550/

这是我的网页

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://code.highcharts.com/highcharts.src.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
    <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $(function () {
                var highOptions = {
                    chart: {
                        type: 'line',
                        renderTo: 'container2',
                        zoomType: 'x',
                        marginTop: 100
                    },
                    title: {
                        text: 'Score'
                    },
                    subtitle: {
                        text: '  '
                    },
                    xAxis: {
                        title: {
                            text: 'XXX'
                        },
                        categories: [],
                        labels: {
                            rotation: 45,
                            step: 1,
                            y: 30
                        }
                    },
                    yAxis: [{ // left y axis
                        title: {
                            text: 'XXX'
                        },
                        min: 0,
                        max: 9,
                        plotLines: [{
                            value: 7.5,
                            color: '#ff0000',
                            width: 2,
                            zIndex: 4,
                            label: {
                                text: 'XXX'
                            }
                        }]
                    }],
                    plotOptions: {
                        column: {
                            dataLabels: {
                                enabled: true,
                                formatter: function () {
                                    return Highcharts.numberFormat(this.y, 1);
                                }
                            }
                        }
                    },
                    legend: {
                        align: 'left',
                        verticalAlign: 'top',
                        y: 20,
                        floating: true,
                        borderWidth: 0
                    },
                    tooltip: {
                        shared: true,
                        crosshairs: true
                    },
                    series: []
                };
                highOptions.xAxis.categories = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8];
                highOptions.subtitle.text = "XXX:";
                chart = new Highcharts.Chart(highOptions);
                var aName = "Fin";
                newLP = [0.1, 5.52, 0.2, 6.16, 0.3, 6.34, 0.4, 6.69, 0.5, 6.36, 0.6, 7.44, 0.7,  
                7.44, 0.8, 7.44];
                    chart.addSeries({
                        name: aName,
                        data: newLP
                    }, false);
                chart.redraw();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container2">
    </div>
    </form>
</body>
</html>

我不知道…为什么它在JSFiddle上运行得很好,但在我的Web应用程序上却不行…没有其他插件安装…请建议

脚本的顺序在这种情况下很重要,正确的顺序FOR CHROME应该是:

<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script src="http://code.highcharts.com/highcharts.src.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

其他浏览器可能有不同的方法来确定首先加载哪个js文件。所以你必须在其他浏览器上测试,如果它们都工作良好。

我在谷歌上搜索了一下这个错误,似乎它总是要处理

<script type="text/javascript">
定义

.

你试过把它改成:

吗?
<script type="text/javascript" language="javascript">