您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页vue3+Echarts(3)

vue3+Echarts(3)

来源:华佗小知识

 helloword初体验

charts系列类型就是图表类型。 系列类型(series.type)至少有: line(折线图)、bar(柱状图)、pie(饼图)、scatter(散点图)、graph(关系图)、tree(树图)

<template>
    <!-- echarts的容器默认宽高是0,如果我们不进行设置的话,页面是不显示的 -->
  <div ref="mychart" id="demoDiv"></div>
</template>

<script>
// 1.引用echarts
// npm install --save echarts
import * as echarts from "echarts"
export default {
    mounted(){
        let myEcharts=echarts.init(this.$refs.myEcharts)

        // 设置参数(对象类型)
        myEcharts.setOption({
            title:{//echarts标题
                text:"helloWord",
            },
            xAxis:{
                data:["EZ","VN","NOC","MF"],
            },
            yAxis:{

            },
            series:{//系列  设置当前数据所能映射出来的图形
                name:"lol英雄大全",
                type:"bar",
                // 柱状图
                data:[6300,4800,3200,600]

            }
        })
    }
}
</script>

<style>
    #demoDiv{
        width: 500px;
        height: 500px;
        border: 1px solid red;
    }
</style>

其中出现了找不到package.json,所以找到了一个有用的链接

Vue打包后Echarts图表不显示问题解决

配置项--title

主标题和副标题

<template>
<div class="about">
<h1>This is an about page</h1>
<div id="main"></div>
</div>
</template>
<script>
import * as echarts from "echarts";
export default {
mounted() {
var myChart = echarts.init(document.getElementById("main"));
myChart.setOption({
title: {
show: true, //显示策略,默认值true,可选为:true(显示) | false(隐藏)
text: "1主标题", //主标题文本,'\n'指定换行
},
// link:'http://www.baidu.com', //主标题文本超链接,默认值true
// target: "self", //指定窗口打开主标题超链接,支持'self' | 'blank',不指定等同
为'blank'(新窗口)
subtext: '副标题', //副标题文本,'\n'指定换行
// sublink: '', //副标题文本超链接
// subtarget: null, //指定窗口打开副标题超链接,支持'self' | 'blank',不指定等同
为'blank'(新窗口)
// x:'center', //水平安放位置,默认为'left',可选为:'center' | 'left' |
'right' | {number}(x坐标,单位px)
// y: 'bottom', //垂直安放位置,默认为top,可选为:'top' | 'bottom' | 'center'
| {number}(y坐标,单位px)
// backgroundColor: 'red', //标题背景颜色,默认'rgba(0,0,0,0)'透明
// borderWidth: 5, //标题边框线宽,单位px,默认为0(无边框)
// borderColor: '#ccffee', //标题边框颜色,默认'#ccc'
// padding: 5, //标题内边距,单位px,默认各方向内边距为5,接受数组分别设定上右下左
边距
// itemGap: 10, //主副标题纵向间隔,单位px,默认为10
// textStyle: { //主标题文本样式{"fontSize": 18,"fontWeight":
"bolder","color": "#333"}
// fontFamily: 'Arial, Verdana, sans...',
// fontSize: 12,
// fontStyle: 'normal',
// fontWeight: 'normal', // },
// subtextStyle: {//副标题文本样式{"color": "#aaa"}
// fontFamily: 'Arial, Verdana, sans...',
// fontSize: 12,
// fontStyle: 'normal',
// fontWeight: 'normal',
// },
// subtextStyle: {
// color: "#a1b2c3", // 副标题文字的颜色。
// fontStyle: "normal", // 副标题文字字体的风格。 'normal' 'italic'
//'oblique'
// fontWeight: "bold", // 副标题文字字体的粗细。 'normal' 'bold'
//'bolder' 'lighter' 500|600。
// fontSize: 18, // 字体大小
// lineHeight: "130", // 行高
// textBorderColor: "red", // 文字本身的描边颜色。
// textBorderWidth: 5, // 文字本身的描边宽度。
// textShadowColor: "transparent", // 文字本身的阴影颜色。
// textShadowBlur: 0, // 文字本身的阴影长度。
// textShadowOffsetX: 0, // 文字本身的阴影 X 偏移。
// textShadowOffsetY: 0, // 文字本身的阴影 Y 偏移。
// },
tooltip: {},
legend: {},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
},
yAxis: {},
series: [
{
name: "销量",
type: "bar",
data: [5, 20, 36, 10, 10, 20],
},
],
});
},
};
</script>
<style>
#main {
width: 500px;
height: 500px;
}
</style>

其中遇到的bug

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务