[英]Code only works in jsfiddle
我的一些代碼有問題。 它只在jsfiddle中運行,我不知道為什么它在Codepen或文件中不起作用。
為什么此代碼僅在jsfiddle中有效? 我在codepen和文件中嘗試了它,但沒有顯示任何內容http://jsfiddle.net/auagufL8/
<script src="http://code.highcharts.com/maps/highmaps.js"></script>
<script src="http://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="http://code.highcharts.com/mapdata/countries/nl/nl-all.js"> </script>
<div id="container"></div>
$(function () {
// Prepare demo data
var data = [
{
"hc-key": "nl-fr",
"value": 0
},
{
"hc-key": "nl-gr",
"value": 1
},
{
"hc-key": "nl-fl",
"value": 2
},
{
"hc-key": "nl-ze",
"value": 3
},
{
"hc-key": "nl-nh",
"value": 4
},
{
"hc-key": "nl-zh",
"value": 5
},
{
"hc-key": "nl-dr",
"value": 6
},
{
"hc-key": "nl-ge",
"value": 7
},
{
"hc-key": "nl-li",
"value": 8
},
{
"hc-key": "nl-ov",
"value": 9
},
{
"hc-key": "nl-nb",
"value": 10
},
{
"hc-key": "nl-ut",
"value": 11
}
];
// Initiate the chart
$('#container').highcharts('Map', {
title : {
text : 'Highmaps basic demo'
},
subtitle : {
text : 'Source map: <a href="http://code.highcharts.com/mapdata/countries/nl/nl-all.js">The Netherlands</a>'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
colorAxis: {
min: 0
},
series : [{
data : data,
mapData: Highcharts.maps['countries/nl/nl-all'],
joinBy: 'hc-key',
name: 'Random data',
states: {
hover: {
color: '#BADA55'
}
},
dataLabels: {
enabled: true,
format: '{point.name}'
}
}]
});
});
#container {
height: 500px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
要在瀏覽器中運行代碼,您需要將其放入<script> //Your code goes here </script>
標記
這個->
#container {
height: 500px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
是CSS,必須在<style>
標記內。
這個->
$(function () {
// Prepare demo data
var data = [
{
"hc-key": "nl-fr",
"value": 0
},
{
"hc-key": "nl-gr",
"value": 1
},
{
"hc-key": "nl-fl",
"value": 2
},
{
"hc-key": "nl-ze",
"value": 3
},
{
"hc-key": "nl-nh",
"value": 4
},
{
"hc-key": "nl-zh",
"value": 5
},
{
"hc-key": "nl-dr",
"value": 6
},
{
"hc-key": "nl-ge",
"value": 7
},
{
"hc-key": "nl-li",
"value": 8
},
{
"hc-key": "nl-ov",
"value": 9
},
{
"hc-key": "nl-nb",
"value": 10
},
{
"hc-key": "nl-ut",
"value": 11
}
];
// Initiate the chart
$('#container').highcharts('Map', {
title : {
text : 'Highmaps basic demo'
},
subtitle : {
text : 'Source map: <a href="http://code.highcharts.com/mapdata/countries/nl/nl-all.js">The Netherlands</a>'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
colorAxis: {
min: 0
},
series : [{
data : data,
mapData: Highcharts.maps['countries/nl/nl-all'],
joinBy: 'hc-key',
name: 'Random data',
states: {
hover: {
color: '#BADA55'
}
},
dataLabels: {
enabled: true,
format: '{point.name}'
}
}]
});
});
是Javascript,必須在<script>
標記內。
哦!
此代碼可完美地在任何地方使用。
要使其在Codepen中正常工作,您需要通過JS面板內的小齒輪添加所有JS資源,並檢查是否已選擇Latest version of jQuery
。 <script>
標記在HTML面板中被忽略。
$(function () { // Prepare demo data var data = [ {"hc-key": "nl-fr","value": 0}, {"hc-key": "nl-gr","value": 1}, {"hc-key": "nl-fl","value": 2}, {"hc-key": "nl-ze","value": 3}, {"hc-key": "nl-nh","value": 4}, {"hc-key": "nl-zh","value": 5}, {"hc-key": "nl-dr","value": 6}, {"hc-key": "nl-ge","value": 7}, {"hc-key": "nl-li","value": 8}, {"hc-key": "nl-ov","value": 9}, {"hc-key": "nl-nb","value": 10}, {"hc-key": "nl-ut","value": 11} ]; // Initiate the chart $('#container').highcharts('Map', { title : { text : 'Highmaps basic demo' }, subtitle : { text : 'Source map: <a href="http://code.highcharts.com/mapdata/countries/nl/nl-all.js">The Netherlands</a>' }, mapNavigation: { enabled: true, buttonOptions: { verticalAlign: 'bottom' } }, colorAxis: { min: 0 }, series : [{ data : data, mapData: Highcharts.maps['countries/nl/nl-all'], joinBy: 'hc-key', name: 'Random data', states: { hover: { color: '#BADA55' } }, dataLabels: { enabled: true, format: '{point.name}' } }] }); });
#container { height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto; } .loading { margin-top: 10em; text-align: center; color: gray; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://code.highcharts.com/maps/highmaps.js"></script> <script src="http://code.highcharts.com/maps/modules/exporting.js"></script> <script src="http://code.highcharts.com/mapdata/countries/nl/nl-all.js"></script> <div id="container"></div>
將所有與CSS相關的文件放在單獨的.css文件中,或將其放在HTML文件中的標記下。 還要將所有腳本放入.js文件中,或將其嵌入HTML文件中的標簽下。
有關更多參考,請訪問此較早的帖子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.