Forum Discussion
How to implement selections based on a categorical dataviewmapping with multiple fields
Hi djpirra
It's difficult to analyse 100% without seeing the rest of your code, but typically the methods you're calling against categorySelectionId to create your selectionId should usually be chained together.
Can you try the following and see if it works?
categoricalDataView.categories.forEach((column: DataViewCategoryColumn) => {
const categorySelectionId = this.host.createSelectionIdBuilder();
_selectionIds.push(
categorySelectionId
.withCategory(column, _i)
.withMeasure(values[0].source.queryName)
.createSelectionId()
);
});
If this isn't working, we might need to get a bit more detail, but let's start here.
Regards,
Daniel
- djpirra6 years agoHelper III
Hi Daniel,
I have tried that approach too...
I cannot use all together because I need to be sending an array to each datapoint since I have several category fields right?
This is the output of console.log for the selection ID:
e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":0}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":1}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Auto":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Malls":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Real Estate":[{"identityIndex":2}]}[]"} VM47262:117515 e {measures: Array(0), dataMap: {…}, key: "{"Customers.Is Retail":[{"identityIndex":2}]}[]"} ... ... ...- dm-p6 years agoSuper User
Hi djpirra,
Based on my understanding of the original code, the output looks okay, although you typically shouldn't need an array for each data point; just a selectionId. However,this will depend on how you are mapping your data, and how you are intending to use it within the visual. I have perhaps wrongly assumed you just wanted an array of all selectionIds available.
Normally, I might have an object array of my categories/values, with the selectionId as an attribute of that particular element, but again, this would depend on my intended use case.
Are you able to share your code at all? It might be more helpful if I can see how you're building your view model and how you are using it when you draw your visual. It might be that we need to make some changes elsewhere and it would be good if I can provide a more targeted answer for you.
Thanks,
Daniel
- dm-p6 years agoSuper User
Hi djpirra,
In terms of selections with the categorical dataViewMapping, you can generate selectionIds for all values of 1 category x 1 grouping (series) x 1 measure. You would add a .withSeries() to your chain to include the grouping, similar to the worked example in the MS doc here.
I have also used this pattern in one of my visuals - this can be seen in how I map my view model here (and here's the dataViewMapping in the capabilities).
If you want to create a selectionId for a context of more categories than this, then you may need to use a table or matrix dataViewMapping (although if you wish to make use of highlighting in your visual, only categorical and matrix would be viable choices).
If you'd want to proceed with using the categorical approach, we should have a look at your code to see if it's possible to re-structure your capabilities or view model to see if we can make valid selectionIds work in this case.
Regards,
Daniel