Forum Discussion

KennethWang's avatar
KennethWang
Frequent Visitor
6 years ago
Solved

Custom Object Formatting

Hi All,   I tried searching for this topic thinking it would be popoular. I just couldn't nail the keywords correctly and nothing comes up.   My question is, when you build a custom visual, is th...
  • dm-p's avatar
    6 years ago

    Hi KennethWang

    This is possible in custom visuals - there is a specific portion of the tutorial in the sample bar chart repo for it, and this is pretty much the scenario you've added the image for.

    This is all covered in the example in more detail but in short, you need to do the following:

    • Define a template object in your capabilities.json you can use for each value.
    • Add a property to your view model for each category's colour.
    • Create selectionIds for the items you want to appear in the properties pane (more about selection) when mapping your view model.
    • Also, when mapping your view model, you need to set the colour by looking in the dataView for any stored values based on this selectionId. If there is nothing found (which there typically won't be the first time), then this needs to be assigned a suitable default.
    • In your enumerateObjectInstances method (in visual.ts), you need to iterate through your categories from your view model and create colour pickers based on the vales set in your view model mapping, and use the template object defined in your capabilities.json above. Each one needs the selectionId also, so it knows where to store the value to in the dataView when the user sets it in the properties pane.

    If this is all set up accordingly, the colour should be stored in the dataView and retrieved correctly for subsequent updates. If the colour changes back after selection, then there is an issue with the selectionId and you might need to review this to get it to work.

    Good luck!

    Daniel