Javascript 海图赢了';Chrome应用程序中的t显示
我正在尝试嵌入highcharts.com上的图表(使用Javascript 海图赢了';Chrome应用程序中的t显示,javascript,jquery,google-chrome-extension,highcharts,google-chrome-app,Javascript,Jquery,Google Chrome Extension,Highcharts,Google Chrome App,我正在尝试嵌入highcharts.com上的图表(使用jquery)。如果我只是在chrome本身中打开windows.html,这些图形就可以正常工作,但它不会加载到我的chrome应用程序中。只是一个空白屏幕。我在文件夹中有所有标准的.js文件,但没有包括在这里 我从这里的例子开始: background.js chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('window
jquery
)。如果我只是在chrome本身中打开windows.html
,这些图形就可以正常工作,但它不会加载到我的chrome应用程序中。只是一个空白屏幕。我在文件夹中有所有标准的.js文件,但没有包括在这里
我从这里的例子开始:
background.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'bounds': {
'width': 400,
'height': 500
}
});
});
清单文件:
{
"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" }
}
window.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>
海图示例
${demo.css}
$(函数(){
$(文档).ready(函数(){
Highcharts.setOptions({
全球:{
useUTC:false
}
});
$(“#容器”)。高图({
图表:{
类型:“样条线”,
动画:Highcharts.svg,//不要在旧IE中设置动画
marginRight:10,
活动:{
加载:函数(){
//设置图表的每秒更新
var系列=本系列[0];
setInterval(函数(){
var x=(新日期()).getTime(),//当前时间
y=数学随机();
系列。添加点([x,y],真,真);
}, 1000);
}
}
},
标题:{
文本:“实时随机数据”
},
xAxis:{
键入:“日期时间”,
像素间隔:150
},
亚克斯:{
标题:{
文本:“值”
},
绘图线:[{
值:0,
宽度:1,
颜色:'#808080'
}]
},
工具提示:{
格式化程序:函数(){
返回“+this.series.name+”
+
Highcharts.dateFormat(“%Y-%m-%d%H:%m:%S',this.x)+'
'+
数字格式(this.y,2);
}
},
图例:{
已启用:false
},
出口:{
已启用:false
},
系列:[{
名称:'随机数据',
数据:(函数(){
//生成一个随机数据数组
var数据=[],
时间=(新日期()).getTime(),
我
对于(i=-19;i而言,答案如下:
现在,您可以确保在代码运行之前已加载所有依赖项。chrome开发工具控制台中是否有任何错误?只需检查未捕获参考错误:未定义Highcharts
将JS代码附加到容器下方,然后重试again@PawełPsztyć这一行?
。进一步挖掘显示了未捕获的参考error位于my exporting.js fileNo中,代码带有$(函数(){…
<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>