[英]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.