我有一個使用 Angular 嵌入的 powerbi 報告。我想洗掉報告的視覺效果。這是我為 deleteVisual 函式實作的代碼。
deleteVisual() {
// Get report
const report = await this.reportObj.getReport();
if (!report){
console.log(“Report Not available”);
return;
}
// Get all the pages of the report
const pages = await report.getPages();
// Check if all the pages of the report deleted
if (pages.length === 0) {
console.log(“No pages found”);
return;
}
// Get active page of the report
const activePage = pages.find((page) => page.isActive);
if (activePage)
// Get all visuals in the active page of the report
const visuals = await activePage.getVisuals();
if (visuals.length === 0) {
console.log('No visuals found.');
return;
}
// Get first visible visual
const visual = visuals.find((v) => v.layout.displayState?.mode ===
models.VisualContainerDisplayMode.Visible);
if (!visual) {
console.log('No visible visual available to delete.');
return;
}
try {
// Delete the visual using powerbi-report-authoring
const response = await activePage.deleteVisual(visual.name);
console.log(`${visual.type} , visual was deleted.`);
return response;
} catch (error) {
console.error(error);
}
}
我收到錯誤訊息說deleteVisual頁面型別上不存在屬性。還有為什么getVisuals,getReport即使deletePage作業正常,但在使用它時會出錯deleteVisual。我想附上錯誤的 ss,但我沒有足夠的聲譽來發布圖片。誰能幫我解決這個問題。
uj5u.com熱心網友回復:
要使用,deleteVisual 請安裝powerbi-report-authoring庫。使用 npm 你可以通過這個命令安裝
npm i powerbi-report-authoring
參考:
https://docs.microsoft.com/javascript/api/overview/powerbi/remove-visual https://www.npmjs.com/package/powerbi-report-authoring
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/445669.html
