简体   繁体   English

Highcharts错误#16:图表未显示在同一页面上

[英]Highcharts Error #16: charts not showing on the same page

i have a website, one page i have successfully added an highchart. 我有一个网站,一个页面我已成功添加了一个高图。

now i copied exactly the same code to the same page, but diffrent asp page, but the first chart has disappeared and the 2nd chart is not showing. 现在我将完全相同的代码复制到同一页面,但不同的asp页面,但第一个图表已经消失,第二个图表没有显示。

it is giving me an error: 它给了我一个错误:

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' 

any ideas why am getting this. 任何想法为什么得到这个。

so my code for the new chart i want: 所以我想要的新图表代码:

 <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>

the chart that is working has the following code: 正在运行的图表具有以下代码:

 <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>

the 2nd chart shows. 第二张图表显示。

but the first chart doesnt, 但第一张图表没有,

both code is in diffrent acsx page! 这两个代码都在不同的acsx页面!

if you go to Given Error Link 如果你去给定错误链接

Highcharts Error #16 Highcharts错误#16

Highcharts already defined in the page 已在页面中定义的Highcharts

This error happens the second time Highcharts or Highstock is loaded in the same page, so the Highcharts namespace is already defined. 第二次在同一页面中加载Highcharts或Highstock时会发生此错误,因此已经定义了Highcharts命名空间。 Keep in mind that the Highcharts.Chart constructor and all features of Highcharts are included in Highstock, so if you are running Chart and StockChart in combination, you only need to load the highstock.js file. 请记住Highcharts.Chart构造函数和Highcharts的所有功能都包含在Highstock中,因此如果您组合运行Chart和StockChart,则只需加载highstock.js文件。

Check whether you copied the scripts library for highcharts second time your code should contain only one time: 检查是否第二次复制脚本库for highcharts,代码应该只包含一次:

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

Edit 编辑

You are trying to show charts in same div as $('#container') Here container is the Id for div. 您试图在与$('#container')相同的div中显示图表。这里的容器是div的Id。 When both ascx render in a page it find the same div with Id container and render the chart which override one of it. 当ascx在页面中呈现时,它会找到与Id容器相同的div,并呈现覆盖其中一个的图表。 so 所以

  1. Make two separate divs: 制作两个独立的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. Remove script(following) from ascx and put it in MasterPage.: 从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. For chart One: 对于图表一:

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

    For chart Two: 对于图表二:

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

You can use this way to wrap the code which runs Highcharts.js library.: 您可以使用这种方式来包装运行Highcharts.js库的代码:

if (!window.HighchartsUniqueName) {
  window.HighchartsUniqueName = true;

  // .. your code which runs Highcharts.js library here ... 

}

I found it here https://stackoverflow.com/a/5154971 and it works for me. 我在这里找到它https://stackoverflow.com/a/5154971 ,它适用于我。

In this way you don't need to put your script in the MasterPage if you don't want. 这样,如果您不想要,则无需将脚本放在MasterPage中。

Be sure to use a very unique name, since it's a global variable. 一定要使用一个非常独特的名称,因为它是一个全局变量。

Also keep in mind that the Highcharts.Chart constructor and all features of Highcharts are included in Highstock, so if you are running Chart and StockChart in combination, you only need to load the highstock.js file or you can wrap it in the same way. 还要记住Highcharts.Chart构造函数和Highcharts的所有功能都包含在Highstock中,所以如果你组合运行Chart和StockChart,你只需要加载highstock.js文件或者你可以用同样的方式包装它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM