czaroentoro

Dynamic Div Container Highchart

Dec 26th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5.         <title>Highcharts Example</title>
  6.  
  7.         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  8.         <style type="text/css">
  9. ${demo.css}
  10.         </style>
  11.         <script type="text/javascript">
  12. $(function () {
  13.  
  14.     var data = [
  15.          [{
  16.             name: 'Jakarta',
  17.             data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  18.         }, {
  19.             name: 'Bangkok',
  20.             data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
  21.         }, {
  22.             name: 'Pnomh Pen',
  23.             data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
  24.         }, {
  25.             name: 'Singapore',
  26.             data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
  27.         }],
  28.  
  29.          [{
  30.             name: 'Tokyo',
  31.             data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 10]
  32.         }, {
  33.             name: 'Seoul',
  34.             data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
  35.         }, {
  36.             name: 'Beijing',
  37.             data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
  38.         }, {
  39.             name: 'New Delhi',
  40.             data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
  41.         }],
  42.  
  43.          [{
  44.             name: 'Paris',
  45.             data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  46.         }, {
  47.             name: 'Rome',
  48.             data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
  49.         }, {
  50.             name: 'Berlin',
  51.             data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
  52.         }, {
  53.             name: 'London',
  54.             data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
  55.         }]
  56.     ];
  57.  
  58.  
  59. $('#container').empty();
  60. data.forEach(function(value, index){
  61.     $('#container').append('<div id="line-container-'+index+'">');
  62. });
  63.  
  64. data.forEach(function(value, index){
  65.     var linecontainer = 'line-container-'+index.toString();
  66.     console.log(linecontainer);
  67.     new Highcharts.chart({
  68.         chart: {
  69.             zoomType: 'x',
  70.             type: 'line',
  71.             renderTo: linecontainer
  72.         },
  73.         title: {
  74.             text: 'Monthly Average Temperature',
  75.             x: -20 //center
  76.         },
  77.         subtitle: {
  78.             text: 'Source: WorldClimate.com',
  79.             x: -20
  80.         },
  81.         xAxis: {
  82.             categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  83.                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  84.         },
  85.         yAxis: {
  86.             title: {
  87.                 text: 'Temperature (°C)'
  88.             },
  89.             plotLines: [{
  90.                 value: 0,
  91.                 width: 1,
  92.                 color: '#808080'
  93.             }]
  94.         },
  95.         tooltip: {
  96.             valueSuffix: '°C'
  97.         },
  98.         legend: {
  99.             layout: 'vertical',
  100.             align: 'right',
  101.             verticalAlign: 'middle',
  102.             borderWidth: 0
  103.         },
  104.         series: value
  105.         });
  106. });
  107.  
  108.    
  109.    
  110. });
  111.         </script>
  112.     </head>
  113.     <body>
  114. <script src="https://code.highcharts.com/highcharts.js"></script>
  115. <script src="https://code.highcharts.com/modules/exporting.js"></script>
  116.  
  117.     <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  118.        
  119.     </body>
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment