Highchart作为模态

时间:2018-02-07 06:47:30

标签: javascript html5 bootstrap-4

我目前正在开发一个带有高图的网页。我需要在点击按钮时显示与模态相同的高图。我正在使用html bootstrap和javascript

这就是我所做的

<div class="container" id = "container1" style = "width: 30%; height: 50%; margin: auto 0 0 0; position: relative; float: left"></div>
  <div class="container" id = "container2" style = "width: 30%; height: 50%; margin: auto 0 0 0; position: relative; float: left"></div>
  <div class="container" id = "container3" style = "width: 30%; height: 50%; margin: auto 0 0 0; position: relative; float: left"></div>
 </div>
 <button type="button" class="btn" data-toggle="modal" data-target="#myModal">click to zoom</button>
 <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
   </div>
  <div class="modal fade" role= "dialog" id = "myModal" style = "width: 50%; height: 70%; position: absolute; float: center">
 </div>

JS:

$(document).ready(function(){             var title = {                文字:'周期档案'
            };             var subtitle = {                文字:'来源:cimtool'             };             var xAxis = {                类别:['Jan','Feb','Mar','Apr','May','Jun',                   'Jul','Aug','Sep','Oct','Nov','Dec']             };             var yAxis = {                标题:{                   文字:'温度(\ xB0C)'                },                plotLines:[{                   值:0,                   宽度:1,                   颜色:'#808080'                }]             };

        var tooltip = {
           valueSuffix: '\xB0C'
        }
        var legend = {
           layout: 'vertical',
           align: 'right',
           verticalAlign: 'middle',
           borderWidth: 0
        };
        var series =  [{
              name: 'Tokyo',
              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]
           }, 
           {
              name: 'New York',
              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]
           }, 
           {
              name: 'Berlin',
              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]
           }, 
           {
              name: 'London',
              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]
           },
           {
              name: 'India',
              data: [5.9, 2.2, 7.7, 6.5, 13.9, 13.2, 14.0, 
                 14.6, 16.2, 8.3, 8.6, 6.8]
           }
        ];

        var json = {};
        json.title = title;
        json.subtitle = subtitle;
        json.xAxis = xAxis;
        json.yAxis = yAxis;
        json.tooltip = tooltip;
        json.legend = legend;
        json.series = series;

        $('#container1').highcharts(json);
        $('#container2').highcharts(json);
        $('#container3').highcharts(json);
        $('#container6').highcharts(json);
        $('#myModal').highcharts(json);
     });

1 个答案:

答案 0 :(得分:0)

请告诉我们您尝试过的内容和示例代码。任何我如何创建一个小提琴,包括bootstarp和jquery以及。

在哪里可以看到一个按钮,请点击它,它会打开模态弹出窗口。该模型包含高图表(基本线)。

HTML:

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div class="container">
  <h2>Activate Modal with JavaScript</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="myBtn">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">

        <div id="container"></div> 



        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

JS:

$(document).ready(function(){
Highcharts.chart('container', {

    title: {
        text: 'Solar Employment Growth by Sector, 2010-2016'
    },

    subtitle: {
        text: 'Source: thesolarfoundation.com'
    },

    yAxis: {
        title: {
            text: 'Number of Employees'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Manufacturing',
        data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
    }, {
        name: 'Sales & Distribution',
        data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
    }, {
        name: 'Project Development',
        data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
    }, {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
});

High chart as modal JS Fiddle