It is not only a fully functional graph visualization library, but also an explorer of data relationships.
!!!###!!!title=How to Reference VChart in Projects——VisActor/VChart tutorial documents!!!###!!!!!!###!!!description=In the [How to Get VChart](./How_to_Get_VChart) chapter, we introduced the ways to get VChart. This chapter will introduce how to reference VChart under these ways.!!!###!!!
How to Reference VChart in Projects
In the How to Get VChart chapter, we introduced the ways to get VChart. This chapter will introduce how to reference VChart under these ways.
Use with cdn
After getting the VChart file from cdn, you can add it to the <script> tag in the HTML file:
Note: When introducing in cdn mode, you need to pay attention to the reference method of VChart:
const vchart = new VChart.default(spec, { dom: 'chart' });
Use with npm
After installing @visactor/vchart into your project via the npm method, you can use it as follows:
Import on demand
@visactor/vchart provides all VChart functionality by default. If your project has strong requirements for code size, you can also import the relevant charts and components on demand.
VChart supports on-demand loading through tree-shaking optimization to reduce the bundle size. If you have not turned off the tree-shaking optimization of your bundle tool, you can register the charts and components you need as shown like the example below:
If the tree-shaking optimization of your bundle tool is turned off, you need to manually import the internal files from @visactor/vchart/esm/xxx, such as @visactor/vchart/esm/core or @visactor/vchart/esm/component, etc. The usage is as follows:
VChart provides support for browser and node environments by default. If your project needs to run in a mini program environment for on-demand loading, please be careful to import the mini program environment code when necessary.
For example, when using in WeChat Mini Program, you need to call registerWXEnv: