首页 >web前端 >uni-app >uniapp中如何引用echarts

uniapp中如何引用echarts

藏色散人
藏色散人原创
2021-01-27 14:34:5213422浏览

uniapp引用echarts的方法:1、通过uni-app官网直接安装echarts插件生成echarts项目模板;2、创建一个新的hello uni-app项目模板;3、把echarts放到components中。

uniapp中如何引用echarts

本教程操作环境:windows7系统、uni-app2.5.1版本,Dell G3电脑。

推荐(免费):uni-app教程

uni-app 引入 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>

1、通过 uni-app 官网直接安装echarts 插件 生成 echarts项目模板

2、在Hbuilder中创建一个新的hello uni-app项目模板

3、把echarts模板中 components 下面的 echarts 放到自己项目components 中

4、把hello uni-app模板中 components 下面的mpvue-echarts 放到自己项目components 中

以上是uniapp中如何引用echarts的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:uniapp h5如何去掉头下一篇:uniapp是啥