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
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 iIn the , register the component as shown in the figure below.
NoteFor the development mode, select professional mode.
For a tutorial on online editing, see Quickly insert ECharts code.
Install ECharts.
Run the following command to install the ECharts type definitions.
pnpm add echarts@5.4.0 -DIn the Third-party Library Dependencies setting for the custom component, enter the
echartsCDN address:https://g.alicdn.com/code/lib/echarts/5.4.0/echarts.min.js
Modify the
qbi.config.tsfile to add anexternalsconfiguration.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' }, });You can also use
npmoryarnto install the type definitions.
In the component management list, find the target component and click the Debug icon.

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.
Create an ECharts instance.
In the
mountmethod, create anechartsinstance.// src/component.ts mount(props: Interfaces.LifecycleProps<Interfaces.ComponentProps>) { // ... this.chart = echarts.init(props.container as HTMLDivElement); this.setOption(props); }Transform the data.
Encapsulate the logic in a
setOptionmethod for reuse during the mount and update phases.customProps.datais 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 eachfieldIdto 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, }), {}, ); }Set the series.
The
seriesproperty configures the data series. Retrieve the dimension and measure fields fromcustomProps.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, // ... }); }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, }, // ... }); }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 withcustomProps.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, }, // ... }); }Create drill-down, interaction, and navigation behaviors.
Quick BI provides the
customProps.dispatchmethod to implement drill-down, interaction, and navigation. ThedataIndexparameter specifies the index of the clicked row incustomProps.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 bundleThe output is generated in the build directory. Upload and publish the component on the Custom Component Platform.
For more information, see Step 3: Publish.