如何使用 getData 获取 webdatarocks 上的列总数?
How to get column total on webdatarocks using getData?
我尝试了给出的建议 here.. 但我仍然无法获得特定列的总详细信息。例如v0。我可以请您分享有关如何在不选择单元格的情况下提取 webdatarocks pivot 中特定列和行详细信息的详细信息。
我还查看了 中给出的建议。我需要额外的帮助..
下面是一段代码。请注意 getTotals
函数 - 它展示了如何在迭代 getData
响应时获取行和列的总数。
let pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
report: {
"dataSource": {
"dataSourceType": "csv",
"filename": "https://cdn.webdatarocks.com/data/data.csv"
},
"slice": {
"rows": [
{
"uniqueName": "Category"
}
],
"columns": [
{
"uniqueName": "Business Type"
},
{
"uniqueName": "Measures"
}
],
"measures": [
{
"uniqueName": "Price"
}
]
}
}
});
webdatarocks.getData({}, getTotals);
function getTotals(rawData) {
let columnTotals = [];
let rowTotals = [];
for (let i = 0; i < rawData.data.length; i++) {
let record = rawData.data[i];
if (record["r0"] == undefined && record["c0"] == undefined) continue;
if (record["r0"] == undefined) {
let _record = {
member: record["c0"],
value: !isNaN(record["v0"]) ? record["v0"] : 0
}; columnTotals.push(_record);
}
if (record["c0"] == undefined) {
let _record = {
member: record["r0"],
value: !isNaN(record["v0"]) ? record["v0"] : 0
}; rowTotals.push(_record);
}
}
console.log(columnTotals);
console.log(rowTotals);
}
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<div id="wdr-component"></div>
我尝试了给出的建议 here.. 但我仍然无法获得特定列的总详细信息。例如v0。我可以请您分享有关如何在不选择单元格的情况下提取 webdatarocks pivot 中特定列和行详细信息的详细信息。
我还查看了
下面是一段代码。请注意 getTotals
函数 - 它展示了如何在迭代 getData
响应时获取行和列的总数。
let pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
report: {
"dataSource": {
"dataSourceType": "csv",
"filename": "https://cdn.webdatarocks.com/data/data.csv"
},
"slice": {
"rows": [
{
"uniqueName": "Category"
}
],
"columns": [
{
"uniqueName": "Business Type"
},
{
"uniqueName": "Measures"
}
],
"measures": [
{
"uniqueName": "Price"
}
]
}
}
});
webdatarocks.getData({}, getTotals);
function getTotals(rawData) {
let columnTotals = [];
let rowTotals = [];
for (let i = 0; i < rawData.data.length; i++) {
let record = rawData.data[i];
if (record["r0"] == undefined && record["c0"] == undefined) continue;
if (record["r0"] == undefined) {
let _record = {
member: record["c0"],
value: !isNaN(record["v0"]) ? record["v0"] : 0
}; columnTotals.push(_record);
}
if (record["c0"] == undefined) {
let _record = {
member: record["r0"],
value: !isNaN(record["v0"]) ? record["v0"] : 0
}; rowTotals.push(_record);
}
}
console.log(columnTotals);
console.log(rowTotals);
}
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<div id="wdr-component"></div>