iT邦幫忙

0

PivotTable.js 入門請教

  • 分享至 

  • xImage

您好:
因為想在WEB 端,有樞紐,小計 等功能的畫面,有看到PivotTable.js

請問是否有用過 PivotTable.js 的前輩,可以請教一下

1.如何引用
https://pivottable.js.org/examples/
官網找不太到

2.從SQL 轉資料 成 JSON 給 PivotTable
要如餵資料
https://github.com/nicolaskruchten/pivottable/wiki/Input-Formats

Arrays of objects
One object per record, the object's keys are the attribute names. See example.

Note: missing attributes or attributes with a value of null are treated as if the value was the string "null".

<script>
    var input = [
        {
            "attr1": "value1_attr1",
            "attr2": "value1_attr2",
            //...
        },
        {
            "attr1": "value2_attr1",
            "attr2": "value2_attr2",
            //...
        },
        //...
    ];
</script>

但他的SAMPLE,卻沒有 input

  $(function(){
        $("#output").pivot(
            [
                {color: "blue", shape: "circle"},
                {color: "red", shape: "triangle"}
            ],
            {
                rows: ["color"],
                cols: ["shape"]
            }
        );
     });
        

3.若要下載目前內容,要如何做?
謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
froce
iT邦大師 1 級 ‧ 2023-08-06 14:10:16
最佳解答

沒用過,只是看你給的文件:

  1. https://pivottable.js.org/examples/simple.html
    檢視原始碼你就能看到怎麼引用了。
    基本上就jQuery、pivot.css、pivot.js

  2. 你自己的第二個連結就有啊。
    https://github.com/nicolaskruchten/pivottable/wiki/Input-Formats

<script>
    Papa.parse("file.csv", { 
        download: true, 
        complete: function(parsed){ $("#output").pivotUI(parsed.data) } 
    });
</script>

parsed.data就是你的 input,這段code就是先用PapaParse去解析csv,然後丟給pivot去顯示。
這邊有api
https://github.com/nicolaskruchten/pivottable/wiki/Parameters

  1. 沒看到選項,不過看demo是你游標指到圖上就能下載png了。
noway iT邦研究生 3 級 ‧ 2023-08-13 17:15:44 檢舉

您好:
謝謝!

但我是想將 結果 匯出成xlsx檔案

我要發表回答

立即登入回答