0

I have used this sample to connect to google Api for charts. It works great.

PHP MySQL Google Chart JSON - Complete Example

I am trying to get graphs and charts sample working with PowerBI.

I have sample.html file. I found this sample here:

https://github.com/Microsoft/PowerBI-visuals/wiki/Displaying-visuals-in-a-single-html-page

The file has reference to 1 css file and 2 javscript file on github.

It displays a blank page.

    <link href="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/visuals.css" rel="stylesheet">
    <script type="text/javascript" src="externals.min.js"></script>  
    <script type="text/javascript" src="powerbi-visuals.js"></script> 

    <script type="text/javascript" src="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/powerbi-visuals.js"> </script>   
    <script type="text/javascript" src="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/powerbi-visuals.min.js"> </script>
    <script type="text/javascript" src="https://github.com/Microsoft/PowerBI-visuals/blob/master/lib/powerbi-externals.d.ts"></script>

    <style>
        .visual {
            'background-color' : 'white',
            'padding' : '10px',
            'margin' : '5px'
        }
    </style>
</head>
<body>

<script type="text/javascript">
    var createDataView = function () {
        var DataViewTransform = powerbi.data.DataViewTransform;

        var fieldExpr = powerbi.data.SQExprBuilder.fieldExpr({ column: { entity: "table1", name: "country" } });

        var categoryValues = ["Australia", "Canada", "France", "Germany", "United Kingdom", "United States"];
        var categoryIdentities = categoryValues.map(function (value) {
            var expr = powerbi.data.SQExprBuilder.equal(fieldExpr, powerbi.data.SQExprBuilder.text(value));
            return powerbi.data.createDataViewScopeIdentity(expr);
        });

        // Metadata, describes the data columns, and provides the visual with hints
        // so it can decide how to best represent the data
        var dataViewMetadata = {
            columns: [
                {
                    displayName: 'Country',
                    queryName: 'Country',
                    type: powerbi.ValueType.fromDescriptor({ text: true })
                },
                {
                    displayName: 'Sales Amount (2014)',
                    isMeasure: true,
                    format: "$0",
                    queryName:'sales1',
                    type: powerbi.ValueType.fromDescriptor({ numeric: true }),
                },
                {
                    displayName: 'Sales Amount (2013)',
                    isMeasure: true,
                    format: "$0",
                    queryName:'sales2',
                    type: powerbi.ValueType.fromDescriptor({ numeric: true })
                }
            ],
        };

        var columns = [
            {
                source: dataViewMetadata.columns[1],
                // Sales Amount for 2014
                values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34],
            },
            {
                source: dataViewMetadata.columns[2],
                // Sales Amount for 2013
                values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34].reverse()
            }
        ];

        var dataValues = DataViewTransform.createValueColumns(columns);

        var dataView = {
            metadata: dataViewMetadata,
            categorical: {
                categories: [{
                    source: dataViewMetadata.columns[0],
                    values: categoryValues,
                    identity: categoryIdentities,
                }],
                values: dataValues
            }
        };

        return dataView;
    };

    function createDefaultStyles(){
        var dataColors = new powerbi.visuals.DataColorPalette();

        return {
            titleText: {
                color: { value: 'rgba(51,51,51,1)' }
            },
            subTitleText: {
                color: { value: 'rgba(145,145,145,1)' }
            },
            colorPalette: {
                dataColors: dataColors,
            },
            labelText: {
                color: {
                    value: 'rgba(51,51,51,1)',
                },
                fontSize: '11px'
            },
            isHighContrast: false,
        };
    }

    function createVisual() {
        var pluginService = powerbi.visuals.visualPluginFactory.create();
        var defaultVisualHostServices = powerbi.visuals.defaultVisualHostServices;
        var width = 600;
        var height = 400;

        var element = $('.visual');
        element.height(height).width(width);


        // Get a plugin
        var visual = pluginService.getPlugin('columnChart').create();

        powerbi.visuals.DefaultVisualHostServices.initialize(); 

        visual.init({
            // empty DOM element the visual should attach to.
            element: element,
            // host services
            host: defaultVisualHostServices,
            style: createDefaultStyles(),
            viewport: {
                height:height,
                width: width
            },
            settings: { slicingEnabled: true },
            interactivity: { isInteractiveLegend: false, selection: false },
            animation: { transitionImmediate: true }
        });

        // Call update to draw the visual with some data
        visual.update({
            dataViews: [createDataView()] ,
            viewport: {
                height: height,
                width: width
            },
            duration: 0
        });
    }
    createVisual();

</script>


<div class="visual"></div>


</body>
</html>
Community
  • 1
  • 1
Vin J
  • 11
  • 5

1 Answers1

1

The reference files are located at this location:

<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/externals.min.js"> </script>
    <script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/powerbi-visuals.js" ></script>
    <script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/PowerBIVisualsPlayground.js"></script>

This is the full working script:

<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>

    <link href="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/visuals.css" rel="stylesheet">
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

    <script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/externals.min.js"> </script>
    <script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/powerbi-visuals.js" ></script>
    <script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/PowerBIVisualsPlayground.js"></script>


    <style>
        .visual {
            'background-color' : 'white',
            'padding' : '10px',
            'margin' : '5px'
        }
    </style>
</head>
<body>
<h1> hello </h1>

<div class="visual"></div>
<script type="text/javascript">
    var createDataView = function () {
        var DataViewTransform = powerbi.data.DataViewTransform;

        var fieldExpr = powerbi.data.SQExprBuilder.fieldExpr({ column: { entity: "table1", name: "country" } });

        var categoryValues = ["Australia", "Canada", "France", "Germany", "United Kingdom", "United States"];
        var categoryIdentities = categoryValues.map(function (value) {
            var expr = powerbi.data.SQExprBuilder.equal(fieldExpr, powerbi.data.SQExprBuilder.text(value));
            return powerbi.data.createDataViewScopeIdentity(expr);
        });

        // Metadata, describes the data columns, and provides the visual with hints
        // so it can decide how to best represent the data
        var dataViewMetadata = {
            columns: [
                {
                    displayName: 'Country',
                    queryName: 'Country',
                    type: powerbi.ValueType.fromDescriptor({ text: true })
                },
                {
                    displayName: 'Sales Amount (2014)',
                    isMeasure: true,
                    format: "$0",
                    queryName:'sales1',
                    type: powerbi.ValueType.fromDescriptor({ numeric: true }),
                },
                {
                    displayName: 'Sales Amount (2013)',
                    isMeasure: true,
                    format: "$0",
                    queryName:'sales2',
                    type: powerbi.ValueType.fromDescriptor({ numeric: true })
                }
            ],
        };

        var columns = [
            {
                source: dataViewMetadata.columns[1],
                // Sales Amount for 2014
                values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34],
            },
            {
                source: dataViewMetadata.columns[2],
                // Sales Amount for 2013
                values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34].reverse()
            }
        ];

        var dataValues = DataViewTransform.createValueColumns(columns);

        var dataView = {
            metadata: dataViewMetadata,
            categorical: {
                categories: [{
                    source: dataViewMetadata.columns[0],
                    values: categoryValues,
                    identity: categoryIdentities,
                }],
                values: dataValues
            }
        };

        return dataView;
    };

    function createDefaultStyles(){
        var dataColors = new powerbi.visuals.DataColorPalette();

        return {
            titleText: {
                color: { value: 'rgba(51,51,51,1)' }
            },
            subTitleText: {
                color: { value: 'rgba(145,145,145,1)' }
            },
            colorPalette: {
                dataColors: dataColors,
            },
            labelText: {
                color: {
                    value: 'rgba(51,51,51,1)',
                },
                fontSize: '11px'
            },
            isHighContrast: false,
        };
    }

    function createVisual() {
        var pluginService = powerbi.visuals.visualPluginFactory.create();
        var defaultVisualHostServices = powerbi.visuals.defaultVisualHostServices;
        var width = 600;
        var height = 400;

        var element = $('.visual');
        element.height(height).width(width);


        // Get a plugin
        var visual = pluginService.getPlugin('columnChart').create();

        powerbi.visuals.DefaultVisualHostServices.initialize(); 

        visual.init({
            // empty DOM element the visual should attach to.
            element: element,
            // host services
            host: defaultVisualHostServices,
            style: createDefaultStyles(),
            viewport: {
                height:height,
                width: width
            },
            settings: { slicingEnabled: true },
            interactivity: { isInteractiveLegend: false, selection: false },
            animation: { transitionImmediate: true }
        });

        // Call update to draw the visual with some data
        visual.update({
            dataViews: [createDataView()] ,
            viewport: {
                height: height,
                width: width
            },
            duration: 0
        });
    }
    createVisual();

</script>




</body>
</html>
Vin J
  • 11
  • 5