谷歌图表
折线图
源代码
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'));
条形图
源代码
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'));
3D 饼图
要以 3D 显示饼图,只需在选项中添加 is3D: true:
var options = {
title: 'World Wide Wine Production',
is3D: true
};