need to show chart on panel of dashboard dynamically

We have complete info in database about panel and chart data. But don't know how to show it dynamically.

We got one reference 

https://www.syncfusion.com/forums/145054/accumulationchart-in-dashboard-panel

but we cann't take hard coded panel here. We need complete information dynamic.

Here is html:-

<ejs-dashboardlayout id='editLayout' #editLayout [columns]="6"
                               [cellAspectRatio]='aspectRatio' [cellSpacing]='cellSpacing' [panels]="panels">
         
</ejs-dashboardlayout>

In this panel, we need to show the chart, but how we can prepare content containing chart selecter.

Please do needful.
  

3 Replies 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team September 17, 2020 07:59 AM UTC

Hi Namita,  
 
Greetings from Syncfusion support. 
 
We have checked your requirement with DashboardLayout component. We suspect that your requirement is any one of the below cases. 
 
Case 1: Dynamically add the panel to the DashboardLayout component. 
 
You can add the panel using addPanel method of DashboardLayout component. Refer to the below code snippet. 
 
<button ejs-button (click)="BtnClick($event)">Add Dashboard panel</button> 
 
<!-- placing the custom component within ng-template --> 
<ng-template #CustomTemplate> 
  <div style="height:100%; width: 100%;" class="templateContent"> 
    <app-card></app-card> 
  </div> 
</ng-template> 
<!-- adding a ng container to append the template in the container --> 
<ng-container #viewContainer></ng-container> 
 
    BtnClick(args) { 
      // adding panel dynamically 
      let panel: PanelModel[] = [{ 
        id: "layout_" + this.count.toString(), 
        'sizeX': 2, 'sizeY': 2, 'row': 0, 'col': 0, 
      }]; 
      this.Dashboard.addPanel(panel[0]); 
      //renders the (CustomTemplate) template in dom 
      const templateValue = this.CustomTemplate.createEmbeddedView(null); 
      // inserts the template into the view container 
      this.viewContainer.insert(templateValue); 
      // Obtaining the content element of the panel 
      let panel_Content = document.getElementById("layout_" + this.count.toString() + "_content"); 
      // appending the template to the panel content element. 
      panel_Content.appendChild(templateValue.rootNodes[0]); 
      this.count= this.count+1; 
    } 
 
Please, download the sample from the following link. 
 
 
Case 2: add the panel content to already existing panel. 
 
You can update the panel using updatePanel method. Refer to the below code snippet. 
 
<button ejs-button (click)="BtnClick($event)">Update Dashboard panel</button> 
   BtnClick(args) { 
      // adding panel dynamically 
      let panel: PanelModel[] = [{ 
        id: "layout_0" , 
        'sizeX': 2, 'sizeY': 2, 'row': 0, 'col': 0, 
      }]; 
      this.Dashboard.updatePanel(panel[0]); 
      //rendes the (CustomTemplate) temaplte in dom 
      const templateValue = this.CustomTemplate.createEmbeddedView(null); 
      // inserts the template into the view container 
      this.viewContainer.insert(templateValue); 
      // Obtaining the content element of the panel 
      let panel_Content = document.getElementById("layout_0_content"); 
      // appending the template to the panel content element. 
      panel_Content.appendChild(templateValue.rootNodes[0]); 
    } 
 
Please, download the sample from the following link. 
 
 
Please, refer the following links to know more about the DashboardLayout component. 
 
UG Documentation 
 
Demo link 
 
API reference  
   
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 



HE Hasin Eshayat December 4, 2020 04:48 AM UTC

Hi there,



I see you have referenced the card component in the app component. I think this solution will work best for 1-5 components. But we have over 20 components and the number will potentially grow. How do I keep that part agnostic and insert it on the fly. I'm happy to keep an entry point component in the TS file. Moreover, a user may not have all of the 20 widget access. 

Another example you gave for replace, I can see it doesn't replace the full component it just adds in the bottom, is it how it meant to work ?


SP Sowmiya Padmanaban Syncfusion Team December 7, 2020 11:55 AM UTC

Hi Namita, 
 
Query1- Dynamic component rendering. 
 
In Angular platform, you have dynamically added the panels in two ways. 
 
1.     Using ng-container reference. 
2.     Dynamically load the already created component. 
 
We have already shared the sample for using container-ref or else, you can load the component the component to the corresponding div dynamically. Please refer the below link. 
 
 
Please, refer the below code snippet. 

 public appendComponent() { 
    const factory = this.cfResolver.resolveComponentFactory(MyDynamicComponent); 
    const componentRef = this.vcRef.createComponent<MyDynamicComponent>( 
      factory 
    ); 
    componentRef.instance.message = "dynamic content"; 
    // append the component to the corresponding panel 
    this.renderer.appendChild( 
      document.getElementById("layout_0_body"), 
      componentRef.injector.get(MyDynamicComponent).elRef.nativeElement 
    ); 
  } 


Please, refer the sample link below. 
 
 
Query2- Another example you gave for replace, I can see it doesn't replace the full component it just adds in the bottom, is it how it meant to work ? 
 
By using updatePanel method, you can update the existing panel content. To achieve this requirement, you need to pass the entire panel setting inside the updatePanel method. 
 
If you want to replace the content of the corresponding panel, first you need to remove the panel content and then add the content to the corresponding panel. 
 
Please, refer the below code snippet. 
 
 BtnClick() { 
    document.getElementById("layout_0_body").children[0].remove(); 
    //rendes the (CustomTemplate) temaplte in dom 
    const templateValue = this.CustomTemplate.createEmbeddedView(null); 
    // inserts the template into the view container 
    this.viewContainer.insert(templateValue); 
    // Obtaining the content element of the panel 
    let panel_Content = document.getElementById("layout_0_body"); 
 
    // appending the template to the panel content element. 
    panel_Content.appendChild(templateValue.rootNodes[0]); 
    this.count = this.count + 1; 
  } 
 
Please, refer the sample link below. 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Marked as answer
Loader.
Up arrow icon