我正在尝试使用jade加载带有Google注释的图表但无法获取要呈现的图表。我能够加载一个饼图,但是在加载需要明确指定容器元素大小的图表时却无法加载。
谷歌的例子 http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html
翻译成了jade(我的代码)
head
script(src='http://www.google.com/jsapi')
script
google.load('visualization', '1', {'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Sold Pencils');
data.addColumn('string', 'title1');
data.addColumn('string', 'text1');
data.addColumn('number', 'Sold Pens');
data.addColumn('string', 'title2');
data.addColumn('string', 'text2');
data.addRows([
[new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
[new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
[new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined],
[new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'],
[new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined],
[new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined]
]);
}
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data, {displayAnnotations: true});
body
a(href='/') Index
p
#chart_div
*和我的css(通过express layout.jade文件加载,注意chart_div加载的蓝色背景)*
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
#chart_div {
background-color: #00B7FF;
width: 700px;
height: 240px;
}
答案 0 :(得分:0)
看起来这只是一个早期关闭我的绘图功能的问题。
添加数据后的}需要在chart.draw之后