javascript - Highcharts 错误 #16 : charts not showing on the same page

标签 javascript asp.net highcharts

我有一个网站,其中一个页面我已经成功添加了一张 Highcharts 。

现在我将完全相同的代码复制到同一页面,但不同的 asp 页面,但是第一个图表消失了,第二个图表没有显示。

它给我一个错误:

Uncaught Highcharts error #16: www.highcharts.com/errors/16 highcharts.js:16
Uncaught SyntaxError: Unexpected token ILLEGAL Dashboard.aspx:657
Uncaught TypeError: Object [object Object] has no method 'highcharts' Dashboard.aspx:405
Uncaught TypeError: Object [object Object] has no method 'draggable' 

任何想法为什么会得到这个。

所以我想要的新图表的代码:

 <script type="text/javascript"
$(function () { 
 $('#container').highcharts({
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Fruit Consumption'
    },
    xAxis: {
        categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
        title: {
            text: 'Fruit eaten'
        }
    },
    series: [{
        name: 'Jane',
        data: [1, 0, 4]
    }, {
        name: 'John',
        data: [5, 7, 3]
    }]
});
});​
></script>

正在运行的图表具有以下代码:

 <script type="text/javascript"     src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>



  <script type="text/javascript">

   $(function() {

       $('#container').highcharts({
           chart: {
               type: 'column'
           },
           title: {
               text: 'Chart'
           },
           xAxis: {
           categories: array1
           },
           yAxis: {
               title: {
                   text: 'aWH'
               }
           },
           tooltip: {
               pointFormat: "Value: {point.y:.1f} mm"
           },

           series: [{

               name: '2011-2012',
               color: '#0000FF',
               data: array
           },
           {

               name: '2012-2013',
               color: '#92D050',
               data: array3
           },


             {

                 color: '#FF0000',
                 name: '2013-2014',
                 data: array2
}]
       });

   });

</script>

第二个图表显示。

但是第一个图表没有,

两个代码都在不同的 acsx 页面中!

最佳答案

如果你去Given Error Link

Highcharts 错误 #16

Highcharts 已在页面中定义

此错误在同一页面中第二次加载 Highcharts 或 Highstock 时发生,因此 Highcharts 命名空间已定义。请记住,Highcharts.Chart 构造函数和 Highcharts 的所有功能都包含在 Highstock 中,因此如果您同时运行 Chart 和 StockChart,则只需加载 highstock.js 文件。

检查你是否第二次复制了 highcharts 的脚本库你的代码应该只包含一次:

<script src="http://code.highcharts.com/highcharts.js"></script>

编辑

您正试图在与 $('#container') 相同的 div 中显示图表,这里容器是 div 的 ID。当两个 ascx 在页面中呈现时,它会找到具有 Id 容器的相同 div 并呈现覆盖其中一个的图表。所以

  1. 制作两个独立的div:

    <div id="container1" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
    <div id="container2" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
    
  2. 从 ascx 中删除脚本(以下)并将其放入 MasterPage。

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
    
  3. 图表一:

    $('#container1').highcharts({//other code
    

    图表二:

     $('#container2').highcharts({//other code
    

关于javascript - Highcharts 错误 #16 : charts not showing on the same page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17364172/

相关文章:

javascript - 保护仅 JavaScript 客户端访问远程 API

javascript - 在服务器端运行javascript

javascript - 更新滚动 : Simplify so it doesn't use JQuery and just the simplest Javascript 上的 CSS 代码

c# - 从 JavaScript 访问 C# 变量

c# - 如何在没有重定向的情况下在 ASP.NET 中显示自定义 404 页面?

javascript - 仅在没有错误的情况下执行 try 语句

javascript - asp.net 未在复选框中显示选中和未选中状态

javascript - 构建要发送到 View 中的 HighCharts 的数据

highcharts - 如何设置 xAxis pointInterval(更新 : tickInterval) in highcharts

javascript - Highstocks - 悬停在一个点上时显示年份