Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
as7
Frequent Visitor

Problem with Selection in custom visualization

I am developing custom Visual in typescript and want to make dropdown having respected data in it.

Ok with Visual Creation, But having problem to implement Selection ID with the data append to my visual.Whenever i use selection ID with data, then my visual fails to load data in it. Please help me with this , regarding selection in custom visual.

 

My code in Visual.ts file is given below:-

 

module powerbi.extensibility.visual {
    //Array to store URL
    interface imageViewModel {
        
        URL: imageDataPoint[];
      
    };
    //Declare URL as string
    interface imageDataPoint {
        imageUrl: string;
        selectionId: ISelectionId;

        
        
    };
    //Data from Power BI to imageViewModel    
    function visualTransform(options: VisualUpdateOptions, host: IVisualHost): imageViewModel {
                let dataViews = options.dataViews;
                let viewModel: imageViewModel = {
                                                    URL: []
                                                    
                                                 };
       if (!dataViews
           || !dataViews[0]
           || !dataViews[0].categorical
           || !dataViews[0].categorical.categories
           || !dataViews[0].categorical.categories[0].values)
                    return viewModel;
                let imageData = dataViews[0].categorical;
                if (imageData) {
                    var imageElement = imageData.categories;
           

           if (imageElement && imageElement.length > 0) {

               for (var i = 0, catLength = imageElement.length; i < catLength; i++) {
                   var k = 0;

                   viewModel.URL.push({
                       imageUrl: <string>imageElement[0].values[i],
                       selectionId: host.createSelectionIdBuilder()
                           .withMeasure(imageElement[0].values[i])
                           .createSelectionId()
                      })
                  

               }
               
               
           }
       }
    

       return viewModel;
    }
    export class Visual implements IVisual {
        
        private image: d3.Selection<SVGElement>;
          
        private host: IVisualHost;        
        private selectionManager: ISelectionManager;
        
                   
       

        static Config = {
            xScalePadding: 0.1,
            solidOpacity: 1,
            transparentOpacity: 0.5
         };
       
        //Element initialization
        constructor(options: VisualConstructorOptions) {
            

            this.image = d3.select(options.element).append("select");
                               
        }

        //Any change tu visualization executes this upadate function
        public update(options: VisualUpdateOptions)  {
            
            let selectionManager = this.selectionManager;
            let viewModel: imageViewModel = visualTransform(options, this.host);
                       
            var zoomFlag = 0;
           
            let divPop = this.image.selectAll('option').data(viewModel.URL);

            divPop.enter().append('option').text(function (d) { return d.imageUrl; });

            
            divPop.exit().remove();
                     
            
            
         
        }
        
       
        public destroy(): void {
            //TODO: Perform any cleanup tasks here
        }
    }
}

 

8 REPLIES 8
KumarDarmesh
Helper IV
Helper IV

What is the purpose for dropdowning? What does the visual do actually

I want visual to have start time and end time inputs . that's why i thinking of having drop down in both , so that it contain 01,02,03 hrs and so on. So, when user select start time 01 hrs and end time 02 hrs , then data filter according to this time period.

and if any visual available in power BI for this type of need then please tell me, otherwise please help. 

Why not creating a calendar table in hours and slicer the hours then?

Thanks for your suggestion.

 

How can I create calendar table in hours as i have created calendar table for date purpose but how can i put time in it and bifurcate it to hours. It will be very helpful if you can show the DAX for it.  

@as7

You can try

 

calendar table in hours =
SELECTCOLUMNS (
    ADDCOLUMNS (
        CROSSJOIN (
            CALENDAR ( "2016-01-01", "2017-12-31" ),
            SELECTCOLUMNS (
                ADDCOLUMNS ( CALENDAR ( "2016-01-01", "2016-01-24" ), "DAY", DAY ( [Date] ) ),
                "DAY", [DAY]
            )
        ),
        "dateTime", [Date]
            + IF ( [DAY] = 24, 0, [DAY] )
                / 24
    ),
    "Date", [Date],
    "dateTime", [dateTime]
)

thanks.

 

But, my requirement is to have a time slicer that can slice my data from one time to other time . and power BI dosen't have such time slicer.

@as7

Do you want to slice a time window like '02:00' to '15:00' for all days? If so, there's some workaround by creating proper lookup tables and measures. 

 

Check a similar thread Specify custom date periods with predefined date periods. The difference is, you have to create start time and end time and filter the data with them, rather than start date and end date in that link.

 

Thanks for this help. But can you please tell me how can i make a table with range of time only not date.

Because Calendar() function is taking date only.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.