我正在尝试实现谷歌可视化 api 从任何文件或数组中绘制直方图。我正在尝试将包含 csv 数据的数组打入 google.visualization.arrayToDataTable()
函数中,但它不起作用。有谁知道如何使用此功能而不是任何实时数据。以下是来自谷歌的示例:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([ // need this to get my any array which will be different as I am getting file from user in my program.
['Dinosaur', 'Length'],
['Acrocanthosaurus (top-spined lizard)', 12.2],
['Albertosaurus (Alberta lizard)', 9.1],
['Allosaurus (other lizard)', 12.2],
['Apatosaurus (deceptive lizard)', 22.9],
['Archaeopteryx (ancient wing)', 0.9],
['Argentinosaurus (Argentina lizard)', 36.6],
['Baryonyx (heavy claws)', 9.1],
var options = {
title: 'Lengths of dinosaurs, in meters',
legend: { position: 'none' }
};
var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
如果无法使用此功能,任何人都有其他建议。此外,由于可扩展性问题,我无法使用 d3。