google.charts.load("current", {
callback: drawChart,
packages: ['corechart']
});
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Metal", "Copper", "Silver", "Gold", "Platinum"],
["Copper", 8.94, null, null, null],
["Silver", null, 10.49, null, null],
["Gold", null, null, 19.30, null],
["Platinum", null, null, null, 21.45]
]);
var view = new google.visualization.DataView(data);
view.setColumns([
0,
1, {calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation"},
2, {calc: "stringify",
sourceColumn: 2,
type: "string",
role: "annotation"},
3, {calc: "stringify",
sourceColumn: 3,
type: "string",
role: "annotation"},
4, {calc: "stringify",
sourceColumn: 4,
type: "string",
role: "annotation"},
]);
var options = {
title: "Density of Precious Metals, in g/cm^3",
width: 600,
height: 400,
legend: {alignment: "right"},
colors: ['#b87333', 'silver', 'gold', '#e5e4e2']
};
var chart = new google.visualization.ColumnChart(document.getElementById("chart_div"));
chart.draw(view, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
哦,让我在那里我需要去!我将数据表更改为: var data = google.visualization.arrayToDataTable [“Metal”,“Copper”,“Silver”,“Gold”,“Platinum”], [“Metal”, 8.94,10.49,19.30,21.45] ]);' 而这对我的目的有效。 –
欢呼!这更有意义... – WhiteHat