data.sort([{column:0,desc:True}]);
下面的示例代码:
google.charts.load("current", {packages: ["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Element", "a", "b", "c", "d"],
["x", 2, 3, 2, 5],
["y", 0, 0, 14, 5],
["z", 7, 3, 4, 10],
["w", 2, 3, 0, 10]]
);
var options = {
bar: {groupWidth: "95%"},
legend: {position: "top"},
chartArea: {
left: 100, top: 50, right: 0, bottom: 100, width: "100%", height: "100%"
},
isStacked: true,
hAxis: {
minValue: 1
}
};
var view = new google.visualization.DataView(data);
var chart = new google.visualization.BarChart(document.getElementById("stackedChart"));
chart.draw(view, options);
}
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<div id="stackedChart" style="width: 900px; height: 500px;"></div>
</body>
</html>