我正在尝试使用gwt原生javascript显示谷歌图表,但我没有得到以下任何输出是我的代码:
GwtChart.html
<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype is not supported. -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="GwtChart.css">
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="gwtchart/gwtchart.nocache.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
</head>
<body>
<div id="visualization" style="width: 600px; height: 400px;"></div>
</body>
</html>
GwtChart.java
public class GwtChart implements EntryPoint {
//ChartServiceAsync chartService=GWT.create(ChartService.class);
public void onModuleLoad() {
createChart() ;
}
private native void createChart()
/*-{
$wnd.google.load('visualization', '1', {packages: ['corechart']});
function drawVisualization() {
// Create and populate the data table.
var data = $wnd.google.visualization.arrayToDataTable([
['Year', 'Austria', 'Bulgaria', 'Denmark', 'Greece'],
['2003', 1336060, 400361, 1001582, 997974],
['2004', 1538156, 366849, 1119450, 941795],
['2005', 1576579, 440514, 993360, 930593],
['2006', 1600652, 434552, 1004163, 897127],
['2007', 1968113, 393032, 979198, 1080887],
['2008', 1901067, 517206, 916965, 1056036]
]);
new $wnd.google.visualization.BarChart($wnd.document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
width:600, height:400,
vAxis: {title: "Year"},
hAxis: {title: "Cups"}}
);
}
$wnd.google.setOnLoadCallback(drawVisualization);
}-*/;
}
任何人都可以帮我用gwt中的原生javascript编写谷歌图表。
答案 0 :(得分:1)
答案 1 :(得分:1)
1)试试这个:
$wnd.google.load("visualization", "1.0", {packages : [ 'corechart' ], callback: drawVisualization});
而不是这两行:
$wnd.google.load('visualization', '1', {packages: ['corechart']});
$wnd.google.setOnLoadCallback(drawVisualization);
或 2)使用
在HTML页面中调用google.load<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {'packages' : ["corechart"] });
</script>