gpt4 book ai didi

javascript - 简单的 Highcharts 但无法运行

转载 作者:行者123 更新时间:2023-12-03 04:28:35 25 4
gpt4 key购买 nike

我是 HTML 和 PHP 新手。我遵循 Highcharts.com 的入门指南,并编写了下面的 HTML 文件。我像index2.htm一样保存它,但它只显示“在脚本之前...”并且没有图表出现。
请帮我。非常感谢

<DOCTYPE HTML>
<html>
<head>
<script src="http://code.highcharts.com/highcharts.js"></script>
<title>Highcharts Example</title>
</head>
<body>
<div id="container" style="width:100%; height:400px;"></div>
<p>Before the script...</p>
<script>
$(function () {
var myChart = Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
},
{
name: 'John',
data: [5, 7, 19]
}]
});
});
</script>

</body>
</html>
</pre>

最佳答案

它不起作用的原因是您将其包装在匿名 jquery 函数中并且没有包含 JQuery 引用。

如果您只是将脚本更改为:

 var myChart = Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
},
{
name: 'John',
data: [5, 7, 19]
}]
});

这是一个简单的 fiddle它的工作原理

关于javascript - 简单的 Highcharts 但无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43595765/

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