- Google 图表教程
- Google 图表 - 主页
- Google 图表 - 概述
- Google 图表 - 环境设置
- 配置语法
- Google 图表 - 区域图
- Google 图表 - 条形图
- Google 图表 - 气泡图
- Google 图表 - 日历图
- Google 图表 - 蜡烛图
- Google 图表 - 柱形图
- Google 图表 - 组合图
- Google 图表 - 直方图
- Google 图表 - 折线图
- Google 图表 - 地图
- Google 图表 - 组织结构图
- Google 图表 - 饼图
- Google 图表 - 桑基图
- Google 图表 - 散点图
- 阶梯区域图
- Google 图表 - 表格图
- Google 图表 - 时间轴图
- Google 图表 - 树状图
- Google 图表 - 趋势线图
- Google 图表有用资源
- Google 图表 - 快速指南
- Google 图表 - 有用资源
- Google 图表 - 讨论
Google 图表 - 前 X 线性图
以下是一个材质线形图的示例,其中 x 轴位于顶部。我们在 Google 图表配置语法 一章中已经看到了用于绘制此图表的配置。下面我们来看一下完成的示例。
配置
我们在此处使用了 axes.x 配置,以便将 x 轴置于图表顶部。
// Set chart options
var options = {
axes: {
x: {
0: {side: 'top'}
}
}
};
示例
googlecharts_line_topx.htm
<html>
<head>
<title>Google Charts Tutorial</title>
<script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
</script>
<script type = "text/javascript">
google.charts.load('current', {packages: ['corechart','line']});
</script>
</head>
<body>
<div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
</div>
<script language = "JavaScript">
function drawChart() {
// Define the chart to be drawn.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Tokyo');
data.addColumn('number', 'New York');
data.addColumn('number', 'Berlin');
data.addColumn('number', 'London');
data.addRows([
['Jan', 7.0, -0.2, -0.9, 3.9],
['Feb', 6.9, 0.8, 0.6, 4.2],
['Mar', 9.5, 5.7, 3.5, 5.7],
['Apr', 14.5, 11.3, 8.4, 8.5],
['May', 18.2, 17.0, 13.5, 11.9],
['Jun', 21.5, 22.0, 17.0, 15.2],
['Jul', 25.2, 24.8, 18.6, 17.0],
['Aug', 26.5, 24.1, 17.9, 16.6],
['Sep', 23.3, 20.1, 14.3, 14.2],
['Oct', 18.3, 14.1, 9.0, 10.3],
['Nov', 13.9, 8.6, 3.9, 6.6],
['Dec', 9.6, 2.5, 1.0, 4.8]
]);
// Set chart options
var options = {
chart: {
title: 'Average Temperatures of Cities',
subtitle: 'Source: worldclimate.com'
},
hAxis: {
title: 'Month',
},
vAxis: {
title: 'Temperature',
},
'width':550,
'height':400,
axes: {
x: {
0: {side: 'top'}
}
}
};
// Instantiate and draw the chart.
var chart = new google.charts.Line(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
</script>
</body>
</html>
结果
验证结果。
googlecharts_line_charts.htm
广告