gpt4 book ai didi

javascript - highcharts 无法在网站中使用

转载 作者:行者123 更新时间:2023-12-03 06:05:03 26 4
gpt4 key购买 nike

我是 javascript 新手。我想在我的网站中使用 highcharts 绘制堆栈条形图。我复制演示代码here ,然后将其粘贴到我的 php 本地主机中,但我的网站中没有 highcharts。有什么问题吗?

代码↓

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#container").highcharts({
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
series: [{
name: 'John',
data: [9, 10, 4, 7, 2]
}, {
name: 'Jane',
data: [8, 5, 3, 2, 1]
}, {
name: 'Joe',
data: [7, 7, 4, 2, 5]
}]
});
});
</script>

</head>

<body>
<h2 align="center">HighCharts.js demo</h2>
Where's the plot?<br>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

</body>
</html>

最佳答案

只需更改调用 jquery 的脚本并使其在 highcharts 之前加载即可。这是必要的,因为 Highcharts 是构建在 jquery 之上的,如果不在 highcharts 源之前加载它,将会导致错误。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>

关于javascript - highcharts 无法在网站中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39584991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com