Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'derivers') #1362

Open
analytics-model opened this issue Mar 10, 2025 · 0 comments
Open

Comments

@analytics-model
Copy link

I encountered a TypeError: Cannot read properties of undefined (reading 'derivers') while running my code. I have confirmed that the pivot.js file exists in our project and that the derivers function is defined. How can I resolve this issue?
The code attached:

import powerbi from "powerbi-visuals-api";
import IVisual = powerbi.extensibility.IVisual;
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
// :white_check_mark: Import jQuery first
import * as $ from "../assets/jquery.min.js";
// :white_check_mark: Import jQuery plugins next
import "../assets/jquery-ui.min.js";
// :white_check_mark: Import PivotTable.js **after** jQuery
(window as any).$ = $;
(window as any).jQuery = $;
import "../assets/pivot.min.js";
import "../assets/pivot.min.css";
// :white_check_mark: Import other libraries after PivotTable.js
import "../assets/plotly.min.js";
import "../assets/d3.js";
import "datamaps";
import "c3";
// Log Exceptions Decorator
export function logExceptions(): MethodDecorator {
    return function (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> {
        return {
            value: function () {
                try {
                    return descriptor.value.apply(this, arguments);
                } catch (e) {
                    const debugArea = this.target.querySelector('#debugLog');
                    debugArea.innerHTML += `<p style="color: red;">Error: ${e}</p>`;
                    console.error(e);
                    throw e;
                }
            }
        }
    }
}
export class Visual implements IVisual {
    private target: HTMLElement;
    private inputElement: HTMLInputElement;
    private dataView: powerbi.DataView;
    // private chart: echarts.ECharts | null = null;
    constructor(options: VisualConstructorOptions) {
        this.target = options.element;
        this.createUI();
    }
    // Applying the logExceptions decorator to the createUI method
    @logExceptions()
    private createUI(): void {
        // Debug Log where Pivot Table will be inserted
        this.target.innerHTML = `
            <div style="padding: 20px; font-family: 'Outfit', sans-serif;">
                <strong>Pivot Table.</strong>
                <div id="debugLog" style="margin-bottom: 8px; font-size: 12px; color: #555;">
                    <strong>Loading Pivot Table...</strong>
                </div>
            </div>`;
        // Pivot utilities
        const derivers = $.pivotUtilities.derivers;
        const renderers = $.extend(
            $.pivotUtilities.renderers,
            $.pivotUtilities.plotly_renderers,
            $.pivotUtilities.d3_renderers,
            $.pivotUtilities.export_renderers
        );
        const data = [
            { color: "blue", shape: "circle" },
            { color: "red", shape: "triangle" },
            { color: "blue", shape: "triangle" },
            { color: "red", shape: "circle" }
        ];
        // Initialize Pivot Table
        $("#debugLog").pivotUI(data, {
            renderers: renderers, // Include custom renderers like Plotly, D3
            cols: ["shape"],      // Columns by shape
            rows: ["color"],      // Rows by color
            rendererName: "Bar Chart", // Set the default renderer to "Bar Chart"
            rendererOptions: {
                // Additional options for the chart can be added here
                chartType: "bar"  // Set default chart type to 'bar'
            }
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant