javascript - 如何在弹出页面上显示 Highchart [由按钮触发]

标签 javascript php html css highcharts

谁能帮忙解决这个问题。 我有两个文件 .php (page.php & chart.php) 我想让图表显示为弹出页面,但不知何故它不起作用。 这是我第一次创建 hightchart。 页面.php

<!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 80%;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

/* The Close Button */
.close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.modal-header {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}
</style>
</head>
<body>

<h2>Animated Modal with Header and Footer</h2>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times;</span>
      <h2>Modal Header</h2>
    </div>
    <div class="modal-body">
    <?php include 'chart.php ';?>
    </div>
    <div class="modal-footer">
      <h3>Modal Footer</h3>
    </div>
  </div>

</div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>

</body>
</html>

图表.php

<DOCTYPE!>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="welcome.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>  
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>

<script>
    $(function () {
    var chart;

    $(document).ready(function () {

        // Build the chart
        $('#days').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Days Frequency'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            series: [{
                type: 'pie',
                name: 'Days Frequency',
                data: [
                    ['Monday',   4],
                    ['Tuesday',       2],
                    ['Wednesday',    1],
                    ['Thursday',     1],
                    ['Friday',   2]
                ]
            }]
        });
    });

});
</script> 
    <title>Behaviour Insight</title>
</head>

<body>
    <div class="container">
        <a href="home.html"><div class="header">
        </div><!--end header -->
                    <div id="days"></div>
    </div><!--end container -->
</body>

</html>

如何让图表显示在弹出窗口中。 谢谢

最佳答案

将 chart.php 更改为这个...

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script>
    $(function() {
        $(document).ready(function() {
            // Build the chart
            $('#days').highcharts({
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                title: {
                    text: 'Days Frequency'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: false
                        },
                        showInLegend: true
                    }
                },
                series: [
                    {
                        type: 'pie',
                        name: 'Days Frequency',
                        data: [
                            ['Monday', 4],
                            ['Tuesday', 2],
                            ['Wednesday', 1],
                            ['Thursday', 1],
                            ['Friday', 2]
                        ]
                    }
                ]
            });
        });
    });
</script> 

<div class="container">
    <a href="home.html"></a>
    <div class="header"></div>
    <div id="days"></div>
</div>

关于javascript - 如何在弹出页面上显示 Highchart [由按钮触发],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406479/

相关文章:

javascript - 同一 html 页面中的多个模式

javascript - 如何在 www 网站中不间断地循环播放声音

javascript - AngularJS 句子和字数统计的两种数据绑定(bind)

javascript - 从图像 URI 创建 Javascript 文件/Blob 对象

PHP - 连接到多个 MySQL 数据库

javascript - 这个 jquery $ ('.some-class' ,$ ('#some-id' )) 是什么意思?

javascript - 如何使 Gulp 任务将项目的每个 jsx 文件转换为不同的 .js 文件?

php - 高亮文本,除了 html 标签

php - 合并变量对 SQL 注入(inject)安全吗?

php - 最简单的多文件上传,最小 "plugins"