JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › General Discussions › Pivot/grouping + charting question
Tagged: pivot table
- This topic has 20 replies, 3 voices, and was last updated 1 year, 9 months ago by pkz.
-
AuthorPosts
-
January 24, 2023 at 11:17 am #104283pkzBlocked
Hi,
Is it possible to do charting in pivot table?
For example in this example: https://www.htmlelements.com/demos/pivottable/selection-details/
is it possible to chart the selection?
January 24, 2023 at 11:35 am #104284adminKeymasterHi,
The only charting in combination with pivot is available here: https://www.htmlelements.com/demos/pivottable/integration-with-chart/
Best regards,
Peter StoevSmart UI Team
https://www.htmlelements.com/January 24, 2023 at 11:55 am #104286pkzBlockedHi,
Thank you for the response! That was helpful!
I’m not able to convert a grid to pivot.
Here is the code: https://codepen.io/ttwer2/pen/ZEjxBzp
I followed the example of converting a table to pivot, but I think I may be missing something. Can you please help?
January 24, 2023 at 12:38 pm #104287adminKeymasterHi pkz,
The provided example has an error – smartPivotTable: At least one column with ‘summary’ is required.”
Best regards,
Peter StoevSmart UI Team
https://www.htmlelements.com/January 24, 2023 at 1:22 pm #104288pkzBlockedGreat! Thank you – that fixed it!
Updated working code: https://codepen.io/ttwer2/pen/ZEjxBzp
Few questions for pivot:
- Is it possible to add multiple summaries of the same column? for example, sum(expenses) as one statistic and avg(expenses) as another?
- Are we able to define custom stats/calculations for the summary?
- I’m not able to use the conditional formatting mode in the above code – am I missing something? i.e nothing happens when I click the button on the top right corner
- In pivot mode > filters, I’m only able to see the numbers as categorical values where I can select or de-select them. How can this be changed to behave as per the type of column? i.e if number -> then range or if text, then string matching
How can I sort the columns in the pivot? for example, the stdevp(income) and the group in the pic below[Solved]- Is it possible (programmatically) to plot the selection in a pivot via charting capabilities of htmlelements? example:
this would come up in a chart with X-axis showing USA,AUS,UK and y-axis showing stddevp(income)
this would be an excellent feature and I’d be grateful and go for the license if you can help with this! 🙂
Thank you!
- This reply was modified 1 year, 10 months ago by pkz.
January 24, 2023 at 4:31 pm #104296ivanpeevskiParticipantHi pkz,
- Â At the moment, we support multiple different summaries only for the smart-grid component.
- Â To achieve this, you could use the onCellRender() callback function. The function is called before each cell render and you can use it to perform the custom calculations and set them as value. Here is a simple example, which changes the value of the ‘USA Income’ summary: codepen
- Â The button is inactive since the div.switchContainer is standing on top of it. If you change it’s position, the button will be active
- At the moment, the pivot designer only supports the categorical filter, however this is a great suggestion, and we will consider adding such option in a future release!
- Yes, it’s possible – the createChart() function simply passes the table data to the smart-chart component. You can create a custom function, which will pass only the selected data – please have a look at the example here codepen
We also have a similar demo on our site here: https://www.htmlelements.com/demos/pivottable/integration-with-chart/
Best regards,
Ivan Peevski
Smart UI Team
https://www.htmlelements.com/January 24, 2023 at 6:13 pm #104297pkzBlockedHi,
Thank you for your response and help!
- No problem
- I don’t understand your solution here. What I would like to see is, for example, a multiplier of x2 for every number of Income. Say, I define a function foo(x){x*2} and apply it to all the column’s values, and I
foo
to be a list of summary types likesum
,stddev
etc., – is this possible? so basically my own summary functions - Got it – thanks for indicating this!
- Thank you! This would definitely be a HUGE addition!
- This is great progress. I just have a few questions regarding this:
- When the chart is generated, I often see empty axis values:|
But this clears up on clicking on the legend again – is there a way to make sure they are always displayed correctly? - I noticed that in your example you have used income as an example, what if I want to support other chart types with say, multiple datasets, how can I easily change the chart type of
smart-chart
(i.e#pivot-chart
)?
- When the chart is generated, I often see empty axis values:|
January 25, 2023 at 12:29 pm #104300ivanpeevskiParticipantHi pkz,
For the custom summary function:
Please see the example here: codepen – it implements a custom summary function which sums 2* value of the data
I have left some comments to make it easier to understand how it works and how to modify it.
Though since this is not an official feature and more of a workaround, there might be some edge cases I have missed where bugs happen.And for the Charting:
Thanks for noting that! I updated the code with a fix here – codepen
Also added some comments to make some of the functions clearer.For example, here is the result when you select Country + Income + Expenses
You can also visit the smart-chart demos page to see some of the possible chart types and customization for the chart.
Best regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/January 25, 2023 at 1:49 pm #104301pkzBlockedHi,
Thank you for the code!
The custom function modification is not exactly what I imagined it to be, but I will inspect the source since I just purchased the license.
Regarding the charting, I’m still seeing a lot lesser occurrences of the chart with no labels. Can you please let me know what change you made or what causes this issue? I saw the code and the logic change seems to be related to multi-bar charting/data management.
Regarding the multi bar, is it possible to chart this:
If I chart this, it comes up with an empty chart.
Thank you for your help!
January 25, 2023 at 5:17 pm #104302ivanpeevskiParticipantHi pkz,
Thanks for reporting that! Here is the update example with the fix included – codepen
If the chart is empty, there is most likely some error when transforming the data from the pivot to the chart
Best regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/January 25, 2023 at 10:52 pm #104303pkzBlockedHi,
Thank you for the update. The fix seems to be partial has different ways of selection have different results and I’m still seeing the empty labels sometimes – it appears only when the chart moves. Is there any way to “redraw” or “refresh” the chart?
In this video, I’ve shown 2 issues:
- The labels not appearing unless I move the chart box
- The chart not displaying data when the _same_ selection is made slightly differently (same data, but different ways of selection)
Video: https://jmp.sh/NW90Ealy
Can you please help with this?
January 26, 2023 at 1:29 pm #104304ivanpeevskiParticipantHi pkz,
Thanks for the feedback!
Here is the updated version: codepen
The Chart can be refreshed by calling smartChart.refresh(), and the animation is controlled with the ‘animation’ property.
Best regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/January 26, 2023 at 3:09 pm #104305pkzBlockedHi,
Thank you again for the help! Everything is perfect now!
One small question: Is it possible to change the
pivot-chart
type dynamically?window.Smart( "#pivot-chart", class { get properties() { return { caption: "", description: "", xAxis: { dataField: "country", gridLines: { visible: false }, type: "basic" }, colorScheme: "scheme28", seriesGroups: [ { type: "column", columnsGapPercent: 50, seriesGapPercent: 0, valueAxis: { description: "Revenue", axisSize: "auto" }, series: [] } ] }; } } );
This is used in the pivot group charting. What if I wanted to dynamically have buttons like line, bar, chart etc.? does it involve changing the data again? or is there a way to pass a parameter to the smart-chart
i.e:
document.querySelector("smart-chart").dataSource = chartDataSource;
so that we can easily switch from line or bar?Thanks again for all your help! Really liking using the library so far!
January 26, 2023 at 4:32 pm #104306ivanpeevskiParticipantHi pkz,
The object “smartChart.seriesGroups[0]” controls the settings of the chart’s type.
In the example, the type is set ‘column’. You can change the type just by changing it to ‘line’ or ‘area’.
To create a bar chart – set the type to ‘column’ and set ‘orientation’ to ‘horizontal’
Best regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/January 26, 2023 at 9:11 pm #104307pkzBlockedHi,
I understand the parameters of the
smartChart
object/class but what I wanted to know was if it was possible to dynamically assign the type. Here is an example of what I would like to do:function process_selection(chart_type){
// assume this function gets the grid’s selection and processes the data so that it can be used for charting – i.e the code inside the chart’s onclick in your codepen.
//how can I use the
chart_type
variable here to change the properties of the already definedwindow.Smart("#pivot-chart",...)
? (since this is what we are using to draw on)//the obvious solution is to re-define the entire smart object with the new chart type – but this seems suboptimal – am I understanding the concept of smart objects correctly?
}
With this function, I can assign to onClick on different chart types:
process_selection('line')
process_selection('bar')
etc.,
-
AuthorPosts
- You must be logged in to reply to this topic.