WeChat Mini Program
Prerequisites must read
WeChat Mini Program limits the code package of the Mini Program to not exceed 2MB due to the consideration of the Mini Program startup speed. The vchart product of the WeChat Mini Program rendering environment we currently built already has 1.82M, so to ensure the package size, we recommend that users Manually introduce vchart to build products for use on WeChat mini programs. We will explain the usage in detail below.
We will still retain the @visactor/wx-vchart
package, and we will continue to optimize the package size in the future. At the same time, we will provide online customization tools to allow users to build products on demand to better control the package size.
Manually introduce vchart build product
Starting from version 1.7.0, we have provided a simple version of the vchart build product by default for WeChat mini programs. The chart types and components it contains are as follows:
- Chart types: line chart, area chart, column chart, pie chart and column-line combination chart
- Component types: axis, discrete legend, tooltip, crosshair and label
Address: index-wx-simple.min.js
If the simple version of the vchart build product we currently provide by default can meet your needs, then you can quote the script first, and we will provide online customization tools later to allow users to build products on demand.
The following is a detailed introduction to how to use it.
how to use
In addition to reading the instructions below, you can also directly move to the demo wx-example.
Used by encapsulating custom components
This step can directly copy the chart in wx-example folder, then replace chart/vchart/index.js with your vchart build product. This code is consistent with the component encapsulation code in @visactor/wx-vchart
. Please see the source code for specific packaging logic.
Use custom components
- Reference components
Just configure the following content in index.json, and use chart
to customize the component.
- Create a chart
Prepare the following xml structure in index.ttml
:
Prepare the required configuration for the chart in index.js
Use @visactor/wx-vchart
@visactor/wx-vchart
is a chart component library encapsulated by VChart for WeChat applet, used to support [WeChat applet] Chart rendering on (https://developers.weixin.qq.com/miniprogram/dev/framework/). Supports introduction through npm
.
This component library only encapsulates the environment. The configuration items and API are exactly the same as VChart. For the corresponding documentation, see VChart.
Environmental requirements
###API
Examples of using the @visactor/wx-vchart
chart component are as follows:
canvas-id
is the chart id, which is consistent with the id of the dom. Please ensure that the id does not repeat.spec
is the core concept of VChart. The spec of cross-end components is consistent with the PC side. For chart configuration examples, please see VChart Chart Example. For users who are not familiar with VChart, you can refer to the Quickly Start VChart tutorial.styles
is the chart container style, which can be used to control the chart width and height.events
is an object array used to register a series of events, which is defined as follows. For details on the specific event name, event filtering configuration and callback function parameters, see VChart Event API
bind:chartinit
is a callback function called after the chart initialization is completed.bind:chartready
is a callback function that is called after the chart has finished rendering.
how to use
In addition to reading the instructions below, you can also go directly to wx-vchart-example.
Prerequisite
Before using the VChart WeChat applet component library, please make sure you have understood the relevant documentation of the WeChat open platform.
Step1: Enable npm capabilities
Open Editor > Tools > Build npm. For specific operations, please read Enable npm capabilities.
**It is important to note: the package.json file of the npm package needs to be within the miniprogramRoot defined by project.config.json. **
Step2: Install
Step3: Create demo page
Please use WeChat developer tools to create page templates
Step4: Reference components
Just configure the following content in index.json, and use chart
to customize the component.
Step5: Create a chart
- Prepare the following xml structure in
index.ttml
:
- Prepare the required configuration of the chart in
index.js
How to develop
Use WeChat developer tools and select [Mini Program] to import this project.
feedback
If you find any problems during use, please give us feedback in GitHub issues. Thank you very much!