<legend id='FJxNT'><style id='FJxNT'><dir id='FJxNT'><q id='FJxNT'></q></dir></style></legend>

<small id='FJxNT'></small><noframes id='FJxNT'>

    <bdo id='FJxNT'></bdo><ul id='FJxNT'></ul>
  1. <i id='FJxNT'><tr id='FJxNT'><dt id='FJxNT'><q id='FJxNT'><span id='FJxNT'><b id='FJxNT'><form id='FJxNT'><ins id='FJxNT'></ins><ul id='FJxNT'></ul><sub id='FJxNT'></sub></form><legend id='FJxNT'></legend><bdo id='FJxNT'><pre id='FJxNT'><center id='FJxNT'></center></pre></bdo></b><th id='FJxNT'></th></span></q></dt></tr></i><div id='FJxNT'><tfoot id='FJxNT'></tfoot><dl id='FJxNT'><fieldset id='FJxNT'></fieldset></dl></div>

      <tfoot id='FJxNT'></tfoot>

      以编程方式透视 Google 可视化数据表

      Programmatically Pivoting the Google Visualization dataTable(以编程方式透视 Google 可视化数据表)

          <legend id='XYEBz'><style id='XYEBz'><dir id='XYEBz'><q id='XYEBz'></q></dir></style></legend>
          <tfoot id='XYEBz'></tfoot>
          • <small id='XYEBz'></small><noframes id='XYEBz'>

            <i id='XYEBz'><tr id='XYEBz'><dt id='XYEBz'><q id='XYEBz'><span id='XYEBz'><b id='XYEBz'><form id='XYEBz'><ins id='XYEBz'></ins><ul id='XYEBz'></ul><sub id='XYEBz'></sub></form><legend id='XYEBz'></legend><bdo id='XYEBz'><pre id='XYEBz'><center id='XYEBz'></center></pre></bdo></b><th id='XYEBz'></th></span></q></dt></tr></i><div id='XYEBz'><tfoot id='XYEBz'></tfoot><dl id='XYEBz'><fieldset id='XYEBz'></fieldset></dl></div>
            • <bdo id='XYEBz'></bdo><ul id='XYEBz'></ul>
                  <tbody id='XYEBz'></tbody>

              • 本文介绍了以编程方式透视 Google 可视化数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我对 this fiddle 感到兴奋,并尝试参考该小提琴创建相同的类型.我的修改示例在 here 中给出,我正在尝试创建如下视图.

                I excited with this fiddle and I tried to create the same kind with reference to that fiddle. My modified sample is given in here and i'm trying to create a view as follows.

                var distinctValues = data.getDistinctValues(2);
                
                    var viewColumns = [1];
                    var groupColumns = [];
                    // build column arrays for the view and grouping
                    for (var i = 0; i < distinctValues.length; i++) {
                        viewColumns.push({
                            type: 'number',
                            label: distinctValues[i],
                            aggregation: google.visualization.data.count
                        });
                        groupColumns.push({
                            column: i+1,
                            type: 'number',
                            //label: distinctValues[i],
                            aggregation: google.visualization.data.sum
                        });
                    }
                

                但我的目标是创建一个如下所示的数据透视表.

                But my aim is to create a pivot table something like as follows.

                ['Column1', 'Column2', 100, 200, 300, 400],
                ['A', 'bar', 0, 1, 1, 0],
                ['A', 'baz', 0, 0, 1, 0],
                ['A', 'foo', 3, 1, 0, 0],
                ['B', 'baz', 0, 1, 0, 0],
                ['B', 'cad', 1, 0, 1, 1],
                ['B', 'qud', 1, 1, 1, 2]
                

                我该如何继续?

                推荐答案

                您必须更改代码中的一些内容.首先,如果您希望 Column1 和 Column2 都在输出中,则 viewColumns 需要同时包含第 0 列和第 1 列.然后,您需要调整添加到 viewColumns 的列:每个列都需要一个计算列中值的 calc 参数.在这种情况下,您希望将列的值与 distinctValues[i] 进行比较,并在匹配时返回 1,在不匹配时返回 0.在 groupColumns 的聚合函数中,使用 sum 而不是 count:

                You have to change a few things in your code. First, the viewColumns needs to contain both columns 0 and 1 to start if you want Column1 and Column2 to both be in the output. Then, you need to adjust the columns you add to the viewColumns: each one needs a calc parameter which calculates the value in the column. In this case, you want to compare the value of the column to distinctValues[i] and return 1 when they match and 0 when they don't. In the aggregation function for groupColumns, use sum instead of count:

                var distinctValues = data.getDistinctValues(2);
                
                var viewColumns = [0, 1];
                var groupColumns = [];
                // build column arrays for the view and grouping
                for (var i = 0; i < distinctValues.length; i++) {
                    viewColumns.push({
                        type: 'number',
                        label: distinctValues[i],
                        calc: (function (x) {
                            return function (dt, row) {
                                return (dt.getValue(row, 2) == x) ? 1 : 0;
                            }
                        })(distinctValues[i])
                    });
                    groupColumns.push({
                        column: i+2,
                        type: 'number',
                        //label: distinctValues[i],
                        aggregation: google.visualization.data.sum
                    });
                }
                

                然后,在分组函数中,传递第一个数组中的第 0 列和第 1 列:

                Then, in the grouping function, pass columns 0 and 1 in the first array:

                var pivotedData = google.visualization.data.group(view, [0, 1], groupColumns);

                var pivotedData = google.visualization.data.group(view, [0, 1], groupColumns);

                在此处查看这些更改:http://jsfiddle.net/asgallant/DUn6B/1/

                这篇关于以编程方式透视 Google 可视化数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)
                  • <bdo id='bnKjj'></bdo><ul id='bnKjj'></ul>
                    1. <i id='bnKjj'><tr id='bnKjj'><dt id='bnKjj'><q id='bnKjj'><span id='bnKjj'><b id='bnKjj'><form id='bnKjj'><ins id='bnKjj'></ins><ul id='bnKjj'></ul><sub id='bnKjj'></sub></form><legend id='bnKjj'></legend><bdo id='bnKjj'><pre id='bnKjj'><center id='bnKjj'></center></pre></bdo></b><th id='bnKjj'></th></span></q></dt></tr></i><div id='bnKjj'><tfoot id='bnKjj'></tfoot><dl id='bnKjj'><fieldset id='bnKjj'></fieldset></dl></div>

                        <tbody id='bnKjj'></tbody>
                      <legend id='bnKjj'><style id='bnKjj'><dir id='bnKjj'><q id='bnKjj'></q></dir></style></legend>

                        1. <small id='bnKjj'></small><noframes id='bnKjj'>

                        2. <tfoot id='bnKjj'></tfoot>