I created a dashboard in PowerBi that I can load in a .cs page using the sample project but I like to try and use the JavaScript API. I tried using the project [GitHub Sample Project https://github.com/Microsoft/PowerBI-JavaScript] But I am getting error about the models is there a different function I would be using? I belive that I have all of the js library installed but the dashboard will not loaded in my html page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.js"></script>
<script src="scripts/step_interact.js"></script>
<script src="scripts/step_embed.js"></script>
<script src="scripts/step_authorize.js"></script>
<script src="/bower_components/powerbi-client/dist/powerbi.js"></script>
<script>
$(document).ready(function () {
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'dashboard',
id: 'dashboardID',
embedUrl: 'https://app.powerbi.com/reportEmbed',
tokenType: models.TokenType.Aad,
accessToken: 'TokenString'
};
var $dashboardContainer = $('#embedContainer');
var dashboard = powerbi.embed($dashboardContainer.get(0), embedConfiguration);
});
</script>
</head >
<body>
<div id="embedContainer"></div>
</body >
</html >
A few things:
From looking at powerbi.js file you're referencing to, try to change the following line:
var models = window['powerbi-client'].models
tovar models = window.powerbi.models
Make sure to use the correct embedURL, you're using /reportEmbed when you should be using /dashboardEmbed.
eventually, your code should look something like this:
You can try this code for displaying PowerBI dashboard using Javascript. All, you will need is valid access token and dashboardId.