Hi,
I would like to ask if it is possible to show a (line) chart in the (last) column of each row of the Pivot Table, that shows the trend of the values of the current row?
I suppose that a method like "columnTemplate" or something similar is needed, as provided in other components, but I didn't find anything similar for the PivotTable...
Thanks.
Hi Laurin,
We are facing difficulties on achieving your requirement in sample level. However, we are currently preparing a sample to fulfil your requirements. We will update the details within two business days (May 23, 2022).
Regards,
Angelin Faith Sheeba
Hi Laurin,
Using queryCellInfo and dataBound events, you can create and add Sparkline chart component to the last column of the Pivot Table. Please refer the below code example.
Code example:
|
queryCellInfo(args) { var colIndex = Number(args.cell.getAttribute('aria-colindex')); if ( args.data[colIndex].isGrandSum && args.data[colIndex].columnHeaders == '' ) { args.cell.innerText = ''; //Here created a div element in the grand total cell to render chart component. var div = document.createElement('div'); div.id = 'chart' + args.data[colIndex].rowIndex; args.cell.appendChild(div);
var data = [];
for (var i = 1; i < Object.keys(args.data).length - 1; i++) { var object = { x: i, xval: args.data[i].columnHeaders, yval: args.data[i].actualValue, }; data.push(object); } obj[args.data[colIndex].rowIndex] = data; //The column value of each row stored as an object that used to render the chart component. } }
dataBound() { // Here the Sparkline chart series created based on the above stored data var keys = Object.keys(obj); for (var i = 0; i < Object.keys(obj).length; i++) { let winloss = new SparklineComponent({ height: '30px', lineWidth: 1, type: 'Line', // You can change chart type here valueType: 'Category', dataSource: obj[keys[i]], xName: 'xval', yName: 'yval', tooltipSettings: { format: '${xval}: ${yval}', trackLineSettings: { color: 'red', width: 1, }, visible: true, }, }); winloss.appendTo('#chart' + keys[i]); } } |
Meanwhile, we have prepared a sample for your reference. Please find it from below link.
Sample: https://stackblitz.com/edit/react-rhevwb-jk4hm4?file=index.js
Please let us know if you have any concerns.
Regards,
Angelin Faith Sheeba.
Thanks, the provided solution works.
However, I have three other questions regarding this topic:
Hi Laurin,
Please find the response below:
|
Query |
Comments |
|
|
Suppose I have a hierarchical rows ("Country" ->
"Product"). When the child rows ("Products") are
collapsed, I don't want to show the sum of all products per country in the
chart of the "country row", but for each product a separate line.
How can I do that? |
we are currently preparing a sample to fulfil your requirements. We will update the details within two business days (July 11, 2022).
|
|
|
In addition, again when collapsing the products, how can I keep the
"country row" empty, in other words, I don't want to show any
values in the various columns (results of aggregation/sum). |
Using showSubTotals property, you can hide the subtotals in the pivot table. Please refer the below code example: Code Example:
|
|
|
How can I disable the collapse button, so that the user is not able to
collapse the "product" rows? |
Kindly use the following CSS to hide the collapse/expand icon in the pivot table at your end sample.
Code Example:
Index.css
|
Meanwhile, we have prepared a sample with above information for your reference.
Sample: https://stackblitz.com/edit/react-1gxtcm?file=index.js,index.css
Please let us know if you have any concerns.
Regards,
Angelin Faith Sheeba
Thanks for the quick reply.
The provided solution of question 2 does not completely fulfill my requirements/problems:
I don't want to show the subtotals when the child-rows are collapsed.
The provided solution hides the sub-totals only when the child-rows are expanded, which is okay, but they should also not appear in collapsed mode.
Hi Laurin,
Please find the response below.
|
Query |
Comments |
|
|
Suppose I have a hierarchical rows ("Country"
-> "Product"). When the child rows ("Products") are
collapsed, I don't want to show the sum of all products per country in the
chart of the "country row", but for each product a separate line.
How can I do that? |
Kindly use the below code example to insert the chart at grand total as per your requirement. Code Example:
Output Screenshot:
Meanwhile, we have prepared a sample with above information for your reference.
Sample: https://stackblitz.com/edit/react-tgzaoi-9nziri?file=index.js |
|
|
In addition, again when collapsing the products, how can I
keep the "country row" empty, in other words, I don't want to show
any values in the various columns (results of aggregation/sum). |
Using aggregateCellInfo event, you can hide the parent subtotals in the pivot table. Please refer the below code example: Code Example:
Output Screenshot: Meanwhile, we have prepared a sample with above information for your reference.
Sample: https://stackblitz.com/edit/react-gwhqsm?file=index.js |
Please let us know if you have any concerns.
Regards,
Angelin Faith Sheeba