[英]Highcharts: how do I call an external .js file in the <head> of my highcharts page
This Highcharts JS function works fine (HTML part not included here):这个 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>
What I'd like to do is put the JS function into a separate file (same folder) and call it in the <head>
of my highcharts page.我想做的是将 JS function 放入一个单独的文件(同一文件夹)中,并在我的 highcharts 页面的
<head>
中调用它。 I've created a separate file called my chart.js containing that function.我创建了一个名为 chart.js 的单独文件,其中包含 function。 How do I call that file when the main highcharts page loads?
当主 highcharts 页面加载时,如何调用该文件?
If your chart.js file is in the same directory the file path would be "./chart.js" in this example如果您的 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.