Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

billbois
New Contributor III

Counting the Slices in a Pie Chart

How can I count the number of slices in a pie chart?

The sheet I'm working on has a slider and a couple of pie charts.  When the user slides the slider, it changes the Dimension Limits on the first pie chart to "Show only values that accumulate to" n% of results, based on revenue, with n being the number specified by the slider.  That part works perfectly.

On a second pie chart, I want to show exactly the same slices (but showing volume instead of revenue).  A little research showed me the way to do this is to have a calculated dimension that's something like:

=Aggr(If(Rank(Sum(Revenue))<=$(vNumberOfSlices), ClientName), ClientName)

But I need to figure out the number of slices in the first pie chart.  I've tried things like GetSelectedCount() and GetAlternativeCount() but they obviously don't work.  Any suggestions?

Thanks!

Bill

1 Solution

Accepted Solutions
MVP
MVP

Re: Counting the Slices in a Pie Chart

You can use triggers on variable change for that (Settings - Document properties - Triggers).

See attached.

4 Replies
MVP
MVP

Re: Counting the Slices in a Pie Chart

I don't think you can retrieve the number of chart elements (like pie slices) from within another chart object.

For special settings, you can maybe work with the aggr() function to rebuild the dimension limit of your first chart in the second (there will probably arise an issue from the fact that aggr() dimensions will be sorted by load order, and you can't force another sort order that you will need to sum up e.g. by largest values).

What you can try is using the same dimension and dimension limits as in your first chart, but use your original expression only for the dimension limit (that will use the first expression), i.e. hide it for presentation (and show a second expression to present your real data, e.g Volume).

Unfortunately, hiding an expression is not an option in a pie chart, but for example in a bar chart. So this method will only work for some chart types.

Alternatively, you can use a pareto select action to actually selecting the dimension values. Doing so will affect both charts.

See attached a sample of both approaches.

Hope this helps,

Stefan

billbois
New Contributor III

Re: Counting the Slices in a Pie Chart

Thanks swuehl, that helps by confirming that objects can't really reference each other and that I'm not missing something obvious.  I'm not sure if PareTo will do the trick because I need it to just happen as soon as the user changes the slider and without clicking a button.  (There again, I may be missing something obvious.) 

MVP
MVP

Re: Counting the Slices in a Pie Chart

You can use triggers on variable change for that (Settings - Document properties - Triggers).

See attached.

billbois
New Contributor III

Re: Counting the Slices in a Pie Chart

Holy Moly, that worked!  I had to undo a lot of my feeble attempts but adding the triggers did the trick.  Thanks for the sample file, it really pointed me in the right direction.

Community Browser