【发布时间】:2019-09-04 09:31:21
【问题描述】:
我创建了一个 API 来从 MySQL 中提取数据。我要做的是将我的 API 的输出连接到 Google 图表(特别是柱形图)。 知道我会怎么做吗? API 输出为 JSON 数据。
谢谢!!
【问题讨论】:
标签: javascript html css mysql node.js
我创建了一个 API 来从 MySQL 中提取数据。我要做的是将我的 API 的输出连接到 Google 图表(特别是柱形图)。 知道我会怎么做吗? API 输出为 JSON 数据。
谢谢!!
【问题讨论】:
标签: javascript html css mysql node.js
您可以通过此示例轻松地将您的 API 数据连接到 Google 地图。
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawTrendlines);
function drawTrendlines() {
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Time of Day');
data.addColumn('number', 'Motivation Level');
data.addColumn('number', 'Energy Level');
data.addRows([
[{v: [8, 0, 0], f: '8 am'}, 1, .25],
[{v: [9, 0, 0], f: '9 am'}, 2, .5],
[{v: [10, 0, 0], f:'10 am'}, 3, 1],
[{v: [11, 0, 0], f: '11 am'}, 4, 2.25],
[{v: [12, 0, 0], f: '12 pm'}, 5, 2.25],
[{v: [13, 0, 0], f: '1 pm'}, 6, 3],
[{v: [14, 0, 0], f: '2 pm'}, 7, 4],
[{v: [15, 0, 0], f: '3 pm'}, 8, 5.25],
[{v: [16, 0, 0], f: '4 pm'}, 9, 7.5],
[{v: [17, 0, 0], f: '5 pm'}, 10, 10],
]);
var options = {
title: 'Motivation and Energy Level Throughout the Day',
trendlines: {
0: {type: 'linear', lineWidth: 5, opacity: .3},
1: {type: 'exponential', lineWidth: 10, opacity: .3}
},
hAxis: {
title: 'Time of Day',
format: 'h:mm a',
viewWindow: {
min: [7, 30, 0],
max: [17, 30, 0]
}
},
vAxis: {
title: 'Rating (scale of 1-10)'
}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
【讨论】: