DEV Community

Siji Chen
Siji Chen

Posted on

How does react-vchart achieve on-demand loading?

Title

How does react-vchart achieve on-demand loading?

Description

H5 project uses vchart volume limit, can it support on-demand loading now? Currently only one funnel chart is used.

Solution

React-VChart itself supports on-demand loading. When VChart needs to be loaded on demand, it is recommended to use the <VChartSimple /> tag,
The <VChartSimple /> component and the <VChart /> component are used in almost the same way. The only difference is that users need to import the VChart constructor class from @viasctor/vchart and pass it to <VChartSimple />; Reference for on-demand import of VChart related documents

interface VChartSimpleProps extends EventsProps {
  /** the spec of chart */
  spec: any;
  /** the options of chart */
  options?: ChartOptions;
  /** call when the chart is rendered */
  onReady?: (instance: VChart, isInitial: boolean) => void;
  /** throw error when chart run into an error */
  onError?: (err: Error) => void;
  /** 
   * use renderSync
   * @since 1.8.3
   **/
  useSyncRender?: boolean;
  /**
   * skip the difference of all functions
   * @since 1.6.5
   **/
  skipFunctionDiff?: boolean;
  /**
   * the constrouctor class of vchart
   * @since 1.8.3
   **/
  vchartConstrouctor: IVChartConstructor;
}
Enter fullscreen mode Exit fullscreen mode

Code Example

/* @refresh reset */
import React, { useMemo } from "react";

import { VChartSimple } from "@visactor/react-vchart";
import { VChart } from "@visactor/vchart/esm/core" 
import { registerFunnelChart } from "@visactor/vchaart/esm/chart/funnel"

// eslint-disable-next-line react-hooks/rules-off-hooks
VChart.useRegisters([registerFunnelChart])

export const FunnelChart = (props) => {
    const spec = useMemo(() =>{
     // ....
    },[]);

    return (
        <React.Fragment>
          <VChartSimple spec={spec}_vchartConstrouctor={VChart} />
        </React.Fragment>
    );
};
Enter fullscreen mode Exit fullscreen mode

Related Documentation

Related Tutorial:

github:https://github.com/VisActor/VChart

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay