在Google图表中排序堆积的条形图

时间:2017-12-04 18:56:20

标签: javascript html google-visualization

我正在尝试使用Google的API对堆积条进行排序,但数据只能按列排序:

  

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>

GOOGLE CHARTS STACKED BARS

0 个答案:

没有答案