折线图
House Prices vs. Size
60
80
100
120
140
0.0
2.5
5.0
7.5
10.0
12.5
15.0
Square Meters
Price in Millions
Price Size
50 7
60 8
70 8
80 9
90 9
100 9
110 10
120 11
130 14
140 14
150 15
源代码
function drawChart() {
// Set Data
var data = google.visualization.arrayToDataTable([
['Price', 'Size'],
[50,7],[60,8],[70,8],[80,9],[90,9],[100,9],
[110,10],[120,11],[130,14],[140,14],[150,15]
]);
// Set Options
var options = {
title: 'House Prices vs Size',
hAxis: {title: 'Square Meters'},
vAxis: {title: 'Price in Millions'},
legend: 'none'
};
// Draw Chart
var chart = new google.visualization.LineChart(document.getElementById('myChart'));
chart.draw(data, options);
}
散点图
要散点图同样的数据,将google.visualization改为LineChart:
var chart = new google.visualization.LineChart(document.getElementById('myChart'));
House Prices vs. Size
0
50
100
150
0.0
2.5
5.0
7.5
10.0
12.5
15.0
Square Meters
Price in Millions
Price Size
50 7
60 8
70 8
80 9
90 9
100 9
110 10
120 11
130 14
140 14
150 15
条形图
World Wide Wine Production
Mhl
0
20
40
60
Italy
France
Spain
USA
Argentina
Contry Mhl
Italy 55
France 49
Spain 44
USA 24
Argentina 15
源代码
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Contry', 'Mhl'],
['Italy', 55],
['France', 49],
['Spain', 44],
['USA', 24],
['Argentina', 15]
]);
var options = {
title: 'World Wide Wine Production'
};
var chart = new google.visualization.BarChart(document.getElementById('myChart'));
chart.draw(data, options);
}
饼图
要将条形图表转换为饼图图表,只需替换:
google.visualization.BarChart
with:
google.visualization.PieChart
var chart = new google.visualization.PieChart(document.getElementById('myChart'));
World Wide Wine Production
Italy
France
Spain
USA
Argentina
29.4%
8%
12.8%
23.5%
26.2%
Contry Mhl
Italy 55
France 49
Spain 44
USA 24
Argentina 15
3D 饼图
要以 3D 显示饼图,只需在选项中添加 is3D: true:
var options = {
title: 'World Wide Wine Production',
is3D: true
};
|