在vue项目中使用echarts

8 篇文章 0 订阅

项目中我们想要数据可视化处理,并且简单明了多元化的展示统计数据。
这种情况下,数据图表展示成为了一种选择。那么图表展示工具Echarts、Highcharts也就呈现在我们眼前。

官方文档:
Echarts:https://www.echartsjs.com/zh/index.html
Highcharts:https://www.highcharts.com.cn/

在html中使用图表我们查看文档都知道,那么在vue项目中我们该如何使用图表

1.安装依赖

npm install echarts --save

2.盒子容器

<div id="date-chart" style="width:400px;height:400px"></div>

3.引入Echarts

import echarts from 'echarts'

4.图表实现

// 初始化
let mychart = echarts.init(document.getElementById('date-chart'))
// 图表设置
let option = {
    animation: true,
    tooltip: {
        trigger: 'item',
        formatter: "{b} : {c}次"
    },
    title: {
        text: 24,
        subtext: "总数",
        x: "center",
        y: "center",
        textStyle: {
            color: "#fff",
            fontSize: 24,
            fontWeight: "normal",
            align: "center",
            marginTop:'-20px',
            width: "200px"
        },
        subtextStyle: {
            color: "#fff",
            fontSize:18,
            fontWeight: "normal",
            align: "center"
        }
    },
    series: [{
        type: "pie",
        center: ["50%", "50%"],
        radius: ["50%", "63%"],
        color: ["#FEE449", "#00FFFF", "#00FFA8", "#9F17FF", "#FFE400", "#F76F01", "#01A4F7", "#FE2C8A"],
        startAngle: 135,
        labelLine: {
            normal: {
                length: 25
            }
        },
        label: {
            normal: {
                formatter: "{b|{b}}  {c|{c}}次 ",
                backgroundColor: "rgba(255, 147, 38, 0)",
                borderColor: "transparent",
                borderRadius: 4,
                rich: {
                    b: {
                        color: "#fff",
                        fontSize: 16,
                        lineHeight: 33
                    },
                    c: {
                        fontSize: 14,
                        // "color": "#eee"
                    }
                },
                textStyle: {
                    color: "#fff",
                    fontSize: 16
                }
            }
        },
        data: [{
            name: "2020-2-5",
            value: 3
        }, {
            name: "2020-2-6",
            value: 2
        }, {
            name: "202-2-7",
            value: 26
        }, {
            name: "2020-2-8",
            value: 24
        }, {
            name: "2020-2-9",
            value: 12
        }, {
            name: "2020-2-10",
            value: 11
        }, {
            name: "2020-2-11",
            value: 3
        }, {
            name: "2020-2-12",
            value: 2
        }]
    }, {
        type: "pie",
        center: ["50%", "50%"],
        radius: ["45%", "46%"],
        hoverAnimation:false ,
        label: {
            show: false
        },
        data: [{
            value: 24,
            name: "总数",
            itemStyle: {
                normal: {
                    color: {
                        x: 0,
                        y: 0,
                        x2: 1,
                        y2: 0,
                        type: "linear",
                        global: false,
                        colorStops: [{
                            offset: 0,
                            color: "#9F17FF"
                        }, {
                            offset: 0.2,
                            color: "#01A4F7"
                        }, {
                            offset: 0.5,
                            color: "#FE2C8A"
                        }, {
                            offset: 0.8,
                            color: "#FEE449"
                        }, {
                            offset: 1,
                            color: "#00FFA8"
                        }]
                    }
                }
            }
        }]
    }]
}
// 图表绘制
mychart.setOption(option)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值