gpt4 book ai didi

javascript - Highcharts 不会在 Chrome 应用中显示

转载 作者:行者123 更新时间:2023-11-30 17:04:47 24 4
gpt4 key购买 nike

我正在尝试嵌入来自 highcharts.com 的图表(使用 jquery)。如果我只是在 chrome 本身中打开 windows.html,这些图表就可以正常工作,但它不会加载到我的 chrome 应用程序中。只是一个空白屏幕。我在文件夹中有所有标准的 .js 文件,但没有在此处包含它们。

我从这里的例子开始: https://developer.chrome.com/apps/first_app

背景.js

chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'bounds': {
'width': 400,
'height': 500
}
});
});

list 文件:

{
"name": "Hello World!",
"description": "My first Chrome App.",
"version": "0.1",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": { "16": "calculator-16.png", "128": "calculator-128.png" }
}

窗口.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>

<script type="text/javascript" src="jquery.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});

$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {

// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;

for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
}())
}]
});
});
});
</script>
</head>
<body>
<script src="highcharts.js"></script>
<script src="exporting.js"></script>

<div id="container" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
</body>
</html>

最佳答案

答案在这个 JSFiddle 中:http://jsfiddle.net/jarrodek/sdr57h3g/

<body>
<!-- Firstly show content, the app will looks more responsive -->
<div id="container" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
<!-- now you have content loaded and you can execute you code -->
<script type="text/javascript" src="jquery.min.js"></script>
<script src="highcharts.js"></script>
<script src="exporting.js"></script>
<!-- move your code to external file (panel below) -->
<script src="myapp.js"></script>
</body>

现在您可以确定在您的代码运行之前已经加载了所有依赖项。

关于javascript - Highcharts 不会在 Chrome 应用中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28220721/

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