Home > Web Front-end > uni-app > How to reference echarts in uniapp

How to reference echarts in uniapp

藏色散人
Release: 2023-01-13 00:44:35
Original
13400 people have browsed it

Methods for uniapp to reference echarts: 1. Install the echarts plug-in directly through the uni-app official website to generate the echarts project template; 2. Create a new hello uni-app project template; 3. Put echarts into components.

How to reference echarts in uniapp

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.

Recommended (free): uni-app tutorial

uni-app introduces echarts

<template>
         <view class="container">
               <view>
                   <view class="canvasView">
                    <mpvue-echarts class="ec-canvas" @onInit="lineInit" canvasId="line" ref="lineChart" />
                </view>
               </view>
           </view>
</template>
 
 
<script>
    // import * as echarts from &#39;@/components/echarts/echarts.simple.min.js&#39;;
    // import mpvueEcharts from &#39;@/components/mpvue-echarts/src/echarts.vue&#39;;
import * as echarts from &#39;../echarts/echarts.simple.min.js&#39;
import mpvueEcharts from &#39;../mpvue-echarts/src/echarts.vue&#39;
    export default {
        data() {
            return {
                updateStatus: false,
                line: {
                    legend: {
                        data: [&#39;邮件营销&#39;]
                    },
                    xAxis: {
                        type: &#39;category&#39;,
                        data: [&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wed&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]
                    },
                    yAxis: {
                        type: &#39;value&#39;,
                        data: []
                    },
                    dataZoom: [{                        type: &#39;slider&#39;,                        start: 30,                        end: 100,                        zoomLock: false,                    }],
                    grid: {
                        left: 40,
                        right: 40,
                        bottom: 20,
                        top: 40,
                        containLabel: true
                    },
                    series: [{                        data: [],
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: &#39;line&#39;,
                        color: [&#39;#5eb4e2&#39;], //折线条的颜色
                    }]
                }
            }
        },
        methods: {
            lineInit(e) {
                let {
                    width,
                    height
                } = e;
                let canvas = this.$refs.lineChart.canvas
                echarts.setCanvasCreator(() => canvas);
                let lineChart = echarts.init(canvas, null, {
                    width: width,
                    height: height
                })
                canvas.setChart(lineChart)
                lineChart.setOption(this.line)
                this.$refs.lineChart.setChart(lineChart)
            },
        },
        components: {
            mpvueEcharts
        }
    }
</script>
 
 
<style>
 
    .ec-canvas {
        display: flex;
        height: 100%;
        flex: 1;
    }
 
    .canvasView {
        width: 700upx;
        height: 500upx;
    }
    
</style>
Copy after login

1. Through uni- The app official website directly installs the echarts plug-in to generate the echarts project template

2. Create a new hello uni-app project template in Hbuilder

3. Put the echarts under components in the echarts template to yourself Project components

4. Put the mpvue-echarts under components in the hello uni-app template into your own project components

The above is the detailed content of How to reference echarts in uniapp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template