All Products
Search
Document Center

Quick BI:End-to-end example: Develop an ECharts chart

Last Updated:Sep 02, 2026

Develop a custom ECharts component for a rounded donut chart in Quick BI professional mode.

Example

效果图For the complete code, see Complete code sample.

Step 1: Create a project

  1. Create a custom component project and install its dependencies.

    For more information, see Development & Debugging > Professional Mode.

    npx create-qbi-app myEcharts
    cd myEcharts
    pnpm i
  2. In the , register the component as shown in the figure below.

    image

    Note

    For the development mode, select professional mode.

    For a tutorial on online editing, see Quickly insert ECharts code.

  3. Install ECharts.

    1. Run the following command to install the ECharts type definitions.

      pnpm add echarts@5.4.0 -D
    2. In the Third-party Library Dependencies setting for the custom component, enter the echarts CDN address: https://g.alicdn.com/code/lib/echarts/5.4.0/echarts.min.jsimage

      Modify the qbi.config.ts file to add an externals configuration.

      import { defineConfig } from '@quickbi/qbi-dev-tools';
      
      export default defineConfig({
        // ...
        externals: {
          lodash: '_',
          react: 'React',
          'react-dom': 'ReactDOM',
          moment: 'moment',
          // Add the following line
          echarts: 'echarts'
        },
      });
    3. You can also use npm or yarn to install the type definitions.

  4. In the component management list, find the target component and click the Debug icon.

    image

    You are automatically redirected to the corresponding dashboard to debug the component. For more information, see Host page debugging.

Step 2: Configure meta

The meta configuration includes settings for the data panel and the style panel.

Configure the data panel

Customize the meta.ts dataSchema to control how the chart retrieves data. You can usually modify the meta file generated from the template. Common properties include:

  • areaName: The display name of the field area.

  • required: Specifies whether a field is mandatory.

  • maxColNum: The maximum number of fields you can drag into this area.

For example, to display one dimension and three measures, change the corresponding maxColNum property:

// meta.ts
const componentMeta: Interfaces.ComponentMeta = {
  propsSchema: {
    dataSchema: {
      areas: [
        {
          id: "drill",
          name: "Drill-down/Dimension",
          queryAxis: "drill",
          rule: {
            fieldTypes: ["dimension"],
            required: false, // Specifies whether this field is required to update the chart.
            /** Limits the number of fields */
            maxColNum: 3,
          },
        },
        {
          id: "area_row",
          name: "Dimension",
          queryAxis: "row",
          rule: {
            fieldTypes: ["dimension"],
            maxColNum: 1, // The maximum number of fields allowed.
            required: true, // Specifies whether this field is required to update the chart.
          },
        },
        {
          id: "area_column",
          name: "Measure",
          queryAxis: "column",
          rule: {
            fieldTypes: ["dimension", "measure"],
            maxColNum: 3, // The maximum number of fields allowed.
            required: true, // Specifies whether this field is required to update the chart.
          },
        },
        {
          id: "filters",
          name: "Filter", // Name of the area.
          queryAxis: "filters",
          rule: {
            fieldTypes: ["dimension", "measure"],
            required: false,
          },
        },
      ],
      resultDisplay: {
        /** Limits the number of returned records. */
        upLimit: 1000,
      },
    },
  },
};
                

This configuration generates the data panel shown in the following figure.配置面板 For more information about dataSchema configuration, see the documentation.

Configure the style panel

The styleSchema property defines the style panel configuration. In this example, the style panel must:

  • Provide an option to show or hide the legend.

  • Provide a numeric input for the start angle.

To meet these requirements, define a checkbox and a number editor by setting type: 'switch' and type: 'number' in the styleSchema. For a list of supported editors, see schema.type.

const componentMeta: Interfaces.ComponentMeta = {
  propsSchema: {
    styleSchema: {
      schema: {
        type: 'object',
        className: 'tabs-uischema-container',
        props: { mode: 'collapse' },
        properties: {
          // Add your custom properties here.
          display: {
            type: 'object',
            title: 'Display Settings',
            properties: {
              showLegend: {
                type: 'switch',
                id: 'showLegend',
                defaultValue: true,
                props: {
                  mode: 'checkbox',
                  label: 'Show Legend',
                },
              },
              startAngle: {
                title: 'Start Angle',
                id: 'startAngle',
                type: 'number',
                defaultValue: 0,
                props: {
                  placeholder: 'Please enter the start angle',
                  maxLength: 140,
                },
              },
            },
          },
        },
      },
    },
  },
};

These editors are automatically generated in the style panel. Access their values from customProps.viewConfig in your custom component.

Step 3: Develop the ECharts chart

Develop the chart by calling the setOption(option) method. The following steps show how to convert Quick BI properties into the parameters that ECharts requires.

  1. Create an ECharts instance.

    In the mount method, create an echarts instance.

        // src/component.ts
      mount(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) {
        // ...
        this.chart = echarts.init(props.container as HTMLDivElement);
        this.setOption(props);
      }
  2. Transform the data.

    Encapsulate the logic in a setOption method for reuse during the mount and update phases.

    customProps.data is a two-dimensional array. customProps.data[i] represents a row of data from the database, containing the values for the configured dimension and measure fields.

    customProps.data[i][j] represents a single cell object that contains a 'value' and a 'fieldId' (the ID of the dimension or measure field). For more information about the data structure, see Custom Component API.

    To simplify value retrieval by fieldId, you can create a map that links each fieldId to its column index.

    // src/component.ts
        setOption(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) {
        // Chart data
        const data = props.customProps.data;
        // Data panel format settings
        const fieldSettingMap = props.customProps.viewConfig.fieldSettingMap;
        // First row of data
        const [firstRow] = data;
        // The position of each field in a row is fixed. Create a map that links the array index to the fieldId to simplify value retrieval.
        const fieldColumnIndexMap: {
          [key: string]: number;
        } = firstRow.reduce(
          (prev, curr, i: number) => ({
            ...prev,
            [curr.fieldId]: i,
          }),
          {},
        );
        }
  3. Set the series.

    The series property configures the data series. Retrieve the dimension and measure fields from customProps.dataConfig.

    // src/component.ts
        setOption(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) {
            // ... data
        // Filter all measures.
        const columnsFields = props.customProps.dataConfig.find(each => each.areaType === 'column')?.fields ?? [];
        // Data panel format settings.
        const fieldSettingMap = props.customProps.viewConfig.fieldSettingMap;
        // Transform the format.
        const series = columnsFields.map((each, i) => {
          const filedSetting = fieldSettingMap[each.fieldId];
          return {
            id: each.fieldId,
            type: 'bar',
            // Get the value for each row based on the fieldId-to-index map.
            data: data.map(row => row[fieldColumnIndexMap[each.fieldId]]?.value),
              coordinateSystem: 'polar',
              // Set an alias.
              name: filedSetting?.aliasName ?? each.showName,
          };
        });
        // ...
        this.chart.setOption({
          series,
          // ...
        });
        }
  4. Set the category.

    Because the rounded donut chart accepts only one dimension, use the first dimension field to set the categories.

    // src/component.ts
        setOption(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) {
        // Filter all dimensions.
        const rowFields = props.customProps.dataConfig.find(each => each.areaType === 'row')?.fields ?? [];
        // The meta file limits it to a single dimension.
        const [onlyRow] = rowFields;
        const category = data.map(row => row[fieldColumnIndexMap[onlyRow?.fieldId]]?.value);
        // ...
        this.chart.setOption({
          radiusAxis: {
            type: 'category',
            data: category,
            z: 10,
          },
          // ...
        });
        }
  5. Read from the style panel.

    Retrieve style panel form values from customProps.viewConfig. In this example, the checkbox editor is named showLegend and the number input is named startAngle, both defined under display. Access them with customProps.viewConfig.display?.showLegend.

    // src/component.ts
        setOption(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) {
        const showLegend = props.customProps.viewConfig.display?.showLegend;
            const startAngle = props.customProps.viewConfig.display?.startAngle;
        // Configure ECharts
        this.chart.setOption({
          angleAxis: {
            startAngle,
          },
          legend: {
            show: viewConfig.display?.showLegend,
            data: legend,
            top: 10,
            padding: 0,
          },
          // ...
        });
        }
  6. Create drill-down, interaction, and navigation behaviors.

    Quick BI provides the customProps.dispatch method to implement drill-down, interaction, and navigation. The dataIndex parameter specifies the index of the clicked row in customProps.data.

    // component.ts
        const dispatch = props.customProps.dispatch;
        if (typeof dispatch === 'function') {
          // Drill-down, interaction, and navigation events
          echarts.on('click', (serie: any) => {
            dispatch({
              type: 'select',
              payload: {
                dataIndex: serie.dataIndex, // dataIndex is the array index of the clicked row in the data object.
              },
            });
          });
          // Click event on a blank area to cancel the current selection.
          echarts.getZr().on('click', function (e) {
            if (!e.target) {
              dispatch({
                type: 'cancelSelect',
              });
            }
          });
        }

After these steps, the basic chart renders. Refine it by modifying styles and adjusting the data format. For details, see the Complete code sample.

Step 4: Bundle the component

Bundle the custom component after development.

npm run build && npm run bundle

The output is generated in the build directory. Upload and publish the component on the Custom Component Platform.

imageFor more information, see Step 3: Publish.