具有数据绑定PowerBI的Highcharts自定义视觉效果

问题描述 投票:3回答:1

Bharath R创建了一个不错的example,其中涉及如何为PowerBI创建高图表自定义视觉。但是,尚未应用任何数据绑定。对于下面的highcharts线图,我想使用变量而不是硬编码值。这样就可以应用数据绑定。

在这里,您可以找到example PowerBI文件,其中包含highcharts定制视觉对象和需要加载到定制视觉对象中的数据。在这个文件中,我制作了两个数据表。我对两个数据表之一没有偏好。重要的是数据的结构方式使得最容易将其加载到可视化图表中。

示例代码(visual.ts)

"use strict";

import "core-js/stable";
import "./../style/visual.less";
import powerbi from "powerbi-visuals-api";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import EnumerateVisualObjectInstancesOptions = powerbi.EnumerateVisualObjectInstancesOptions;
import VisualObjectInstance = powerbi.VisualObjectInstance;
import DataView = powerbi.DataView;
import VisualObjectInstanceEnumerationObject = powerbi.VisualObjectInstanceEnumerationObject;

import * as Highcharts from 'highcharts';
import * as Exporting from 'highcharts/modules/exporting';

import { VisualSettings } from "./settings";
export class Visual implements IVisual {
private target: HTMLElement;
private settings: VisualSettings;

    constructor(options: VisualConstructorOptions) {
        console.log('Visual constructor', options);
        this.target = options.element;
    }

    public update(options: VisualUpdateOptions) {
        this.settings = Visual.parseSettings(options && options.dataViews && options.dataViews[0]);
        console.log('Visual update', options);
        var optionMain=this.target;

        /**
         * Code to add highcharts
         */

        Highcharts.chart(optionMain.id, {

            title: {
                text: 'Solar Employment Growth by Sector, 2010-2016'
            },

            subtitle: {
                text: 'Source: thesolarfoundation.com'
            },

            xAxis: {
                categories: ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017']
            },

            yAxis: {
                title: {
                    text: 'Number of Employees'
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle'
            },

            plotOptions: {
                series: {
                    label: {
                        connectorAllowed: false
                    }
                }
            },

            series: [{
                name: 'Installation',
                data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
                type: undefined
            }, {
                name: 'Manufacturing',
                data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
                type: undefined
            }, {
                name: 'Sales & Distribution',
                data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
                type: undefined
            }, {
                name: 'Project Development',
                data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227],
                type: undefined
            }, {
                name: 'Other',
                data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
                type: undefined
            }],

            responsive: {
                rules: [{
                    condition: {
                        maxWidth: 500
                    },
                    chartOptions: {
                        legend: {
                            layout: 'horizontal',
                            align: 'center',
                            verticalAlign: 'bottom'
                        }
                    }
                }]
            }

        });



    }

    private static parseSettings(dataView: DataView): VisualSettings {
        return VisualSettings.parse(dataView) as VisualSettings;
    }

    /**
     * This function gets called for each of the objects defined in the capabilities files and allows you to select which of the
     * objects and properties you want to expose to the users in the property pane.
     *
     */
    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
        return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options);
    }
}
highcharts data-binding powerbi powerbi-custom-visuals data-mapping
1个回答
0
投票

查看链接和https://docs.microsoft.com/en-us/power-bi/developer/visuals/dataview-mappings之间的差异。似乎已弃用microsoft.github.io/PowerBI-visuals/docs/concepts/…,并且某些功能和synthax已更改。

在您的示例中,我没有在dataViewMappings中看到您的定义。

这里,当我完全遵循两个链接(不推荐使用)中指示的步骤,并且在这里动态加载结果时,会发生什么。尝试按照本教程进行操作,如果问题仍然存在,请返回。

© www.soinside.com 2019 - 2024. All rights reserved.