簡體   English   中英

Highcharts:如何在我的 highcharts 頁面中調用 external.js 文件

[英]Highcharts: how do I call an external .js file in the <head> of my highcharts page

這個 Highcharts JS function 工作正常(此處不包括 HTML 部分):

<html>
<head>
    <title>Highcharts Chart with HTML Data</title>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/data.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <script src="https://code.highcharts.com/modules/export-data.js"></script>


   <script type="text/javascript">
        $(function(mychart) {
            Highcharts.chart('container', {
                data: {
                    table: document.getElementById('datatable'),
                    startRow: 0,
                    endRow: 10
                },              
                chart: {
                    type: 'spline'
                },
                xAxis: {
                    type: 'category'
                  },
                title: {
                    text: 'Tides for: Cundy Harbor, New Meadows River, Casco Bay, Maine'
                },
                yAxis: {
                    title: {
                      text: 'Height of tide<br>in feet.'
                        },
                        gridLineColor: '#197F07',
                        gridLineWidth: 0,
                        lineWidth:1,
                        plotLines: [{
                            color: '#FF0000',
                            width: 1,
                            value: 0
                    }]
                },
                tooltip: {
                    formatter: function() {
                        return '<b>' + this.series.name + '</b><br>' +
                            this.point.y + ' ft.<br>' + this.point.name;
                    }
                }
            });
        });
</script>

</head>

我想做的是將 JS function 放入一個單獨的文件(同一文件夾)中,並在我的 highcharts 頁面的<head>中調用它。 我創建了一個名為 chart.js 的單獨文件,其中包含 function。 當主 highcharts 頁面加載時,如何調用該文件?

如果您的 chart.js 文件位於同一目錄中,則此示例中的文件路徑為“./chart.js”

<html>
<head>
    <title>Highcharts Chart with HTML Data</title>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/data.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <script src="https://code.highcharts.com/modules/export-data.js"></script>


   <script src="/file/path/to/chart.js"></script>

</head>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM