Skip to main content

Use Case

In some scenarios, you may need components in YiDA custom pages that are not available in the YiDA component library, such as ECharts chart components. Developers can import ECharts.js into custom pages to visualize YiDA data. This tutorial shows how to import external JS libraries into custom pages to meet complex scenario requirements.

Video Tutorial

Steps

Step 1: Configure JSX Component Attributes

Create a custom page and drag a JSX component from the component library onto the center canvas. Then set its id attribute and styles. Steps:
  1. Select the JSX component on the page. In the right-side attribute panel, click the Edit JSX Code button.
  2. Add the id="main" field after div.
  3. Click the Style tab on the right, click Source Editing, and enter #main { height: 400px }.
See the illustration below:

Step 2: Bind the didmount Lifecycle to Load Remote JS Resources

Load JS resources from a CDN in the page’s didMount lifecycle (for more information about custom page lifecycles, see the documentation). Copy the following code directly into the didMount section of the custom page action panel, as shown below: The loadScript method code is as follows:

Step 3: Render a Radar Chart with ECharts

Based on the JS implementation above, after the remote JS resource is loaded, a radar function runs to render the Radar. Add a radar function in the action panel to render the Radar into the JSX component created in Step 1. For details on Radar usage, refer to the ECharts documentation. The radar method code is as follows:

Step 3: Bind Data Variables

The radar method above reads two variables from state: nameArr and dataArr. Therefore, you need to set the data variables for the Radar, as shown below:

Display Effect

Visit the official ECharts Import Example to view the effect and implementation details. The final display is shown below: