echarts的基本使用以及如何使用官方实例的方法 - z_xun

xiaoxiaoxun 2021-11-05 原文


echarts的基本使用以及如何使用官方实例的方法


<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="box" style="width: 600px;height:400px;"></div>   //如果需要改背景色直接在这里修改便可以

 

 
export default {
data() {
return {
//调用了eacharts官方实例的 ,这里写option的属性
// 指定图表的配置项和数据
option: {
backgroundColor: "#2c343c",

title: {
text: "Customized Pie",
left: "center",
top: 20,
textStyle: {
color: "#ccc"
}
},

tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)"
},

visualMap: {
show: false,
min: 80,
max: 600,
inRange: {
colorLightness: [0, 1]
}
},
series: [
{
name: "访问来源",
type: "pie",
radius: "55%",
center: ["50%", "50%"],
data: [
{ value: 335, name: "直接访问" },
{ value: 310, name: "邮件营销" },
{ value: 274, name: "联盟广告" },
{ value: 235, name: "视频广告" },
{ value: 400, name: "搜索引擎" }
].sort(function(a, b) {
return a.value - b.value;
}),
roseType: "radius",
label: {
normal: {
textStyle: {
color: "rgba(255, 255, 255, 0.3)"
}
}
},
labelLine: {
normal: {
lineStyle: {
color: "rgba(255, 255, 255, 0.3)"
},
smooth: 0.2,
length: 10,
length2: 20
}
},
itemStyle: {
normal: {
color: "#c23531",
shadowBlur: 200,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
},

animationType: "scale",
animationEasing: "elasticOut",
animationDelay: function(idx) {
return Math.random() * 200;
}
}
]
},
};
},

 

methods: {
 customized() {
            var myChart = echarts.init(document.getElementById(\’box\’));
            myChart.setOption(this.option,true);
        }
 

 

 
 
最后在main.js入口文件中 全局引入挂载
// 引入echarts
// import echarts from \'echarts\'
//挂载到实例对象上
// Vue.prototype.$echarts =echarts
 

 

 
 
==================================

需要加下面两句  这个是main全局引入的
import echarts from \'echarts\'
Vue.use(echarts)//全局使用echarts
 mounted() {
        this.customized();
        let _this = this;
        _this.$nextTick(() => {
            let bargraph = echarts.init(_this.$refs.barg);
            bargraph.setOption(_this.option);
            window.addEventListener(\’resize\’, bargraph.resize);
        });
    },

 

        // 客户概况(数据中心)
        getClientGeneralSituation() {
            const start = new Date(new Date(new Date().toLocaleDateString()).getTime());
            // console.log(parseInt(start.getTime() / 1000) - 86400, \'js 取得今天0点:\'); //Mon Dec 04 2017 00:00:00 GMT+0800 (中国标准时间)
            const end = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
            // console.log(parseInt(end.getTime() / 1000) - 86400, \'js 取得今天 23:59:59\'); //Mon Dec 04 2017 23:59:59 GMT+0800 (中国标准时间)
            this.$axios
                .post(\'/platformapi/company_wechat/getClientContactStatistics\', {
                    start_time: this.start_time ? this.start_time : parseInt(start.getTime() / 1000) - 86400,
                    end_time: this.end_time ? this.end_time : parseInt(end.getTime() / 1000) - 86400,
                    userid: this.suserIdArr,
                    section_id: this.sectionIdArr,
                    type: this.type //[必填] type==1 添加客户 type==2 与客户聊天 type==3 客户流失
                })
                .then(({ data }) => {
                    console.log(data, \'客户概况(数据中心)\');
                    if (!data.data.data) {
                        return;
                    }

                    this.option.legend.data = \'\';
                    this.option.xAxis.data = \'\';
                    this.total_count = data.data.total_count; //总人数
                    this.newly_increased = data.data.newly_increased; // 昨日新增
                    this.option.legend.data = data.data.data.ordertype;
                    this.option.xAxis.data = data.data.data.day;
                    // let Max = data.data.data.all[0].data[0];
                    // data.data.data.all.forEach((item, index) => {
                    //     if (index == 0) {
                    //         item.lineStyle = {
                    //             color: \'#4AB5E5\'
                    //         };
                    //     }
                    //     if (index == 1) {
                    //         item.lineStyle = {
                    //             color: \'#6BE6C1\'
                    //         };
                    //     }
                    //     if (index == 2) {
                    //         item.lineStyle = {
                    //             color: \'#626C91\'
                    //         };
                    //     }
                    //     item.data.forEach((node) => {
                    //         if (Max < node) {
                    //             Max = node;
                    //         }
                    //     });
                    // });
                    // this.option.yAxis.max = \'\';
                    // this.option.yAxis.max = Max;
                    this.series = [];
                    console.log(data.data.data.all, \'data.data.data.all\');
                    data.data.data.all.forEach((item, index) => {
                        // this.series.push({ name: item.name, type: item.type, stack: \'总量\', data: item.data, series: [] });
                        this.series[index] = { name: item.name, type: item.type, data: item.data, series: [] };
                    });
                    console.log(this.series, \'this.series1\');
                    console.log(this.type, \'this.type\');
                    this.series.forEach((item) => {
                        item.data.forEach((node) => {
                            if (this.type == 1) {
                                item.series.push(node.new_apply_cnt);
                                item.series.push(node.new_contact_cnt);
                            }
                            if (this.type == 2) {
                                item.series.push(node.chat_cnt);
                                item.series.push(node.message_cnt);
                                item.series.push(node.reply_percentage);
                                item.series.push(node.avg_reply_time);
                            }
                             if (this.type == 3) {
                                item.series.push(node.negative_feedback_cnt);
                            }
                        });
                    });
                    this.series.forEach((item) => {
                        item.data.forEach((node) => {
                            item.data = item.series;
                        });
                    });
                    // this.option.series = data.data.data.all;
                    // this.option.series = [1];
                    this.option.series = this.series;
                    this.customized();
                });
        },
        customized() {
            var myChart = echarts.init(document.getElementById(\'box\'));
            myChart.setOption(this.option, true);
        }

 

发表于
2019-07-12 21:11 
z_xun 
阅读(3057
评论(2
编辑 
收藏 
举报

 

版权声明:本文为xiaoxiaoxun原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiaoxiaoxun/p/11178431.html

echarts的基本使用以及如何使用官方实例的方法 - z_xun的更多相关文章

  1. 机器学习中的损失函数 – Insolia

    机器学习中的损失函数 损失函数(loss function)是用来估量你模型的预测值f(x)与真实值Y的不一致 […]...

  2. windows10 cmd/bash/powershell字体修改 – 诸葛孔明没灯

    windows10 cmd/bash/powershell字体修改 个人比较喜欢Ubuntu Mono字体,所 […]...

  3. apache 二级域名设置完整步骤 – 防空洞123

    apache 二级域名设置完整步骤 http://blog.csdn.net/cz666/article/de […]...

  4. 关于原码、反码和补码 – 错与对并不是绝对的

    关于原码、反码和补码 原码,就是二进制定点表示法,即最高位为符号位,“0”表示正,“1”表示负,其余表示数值的 […]...

  5. 一个完整JavaWeb项目历程01 — Hello World

    前言 打算写一个从Hello World到完整JavaWeb项目的系列,记录一下学习Java的过程;可能会包含 […]...

  6. 【SQL】- 基础知识梳理(四) – 存储过程

    存储过程的概念 存储过程Procedure是一组为了完成特定功能的SQL语句集合,经编译后存储在数据库中,用户 […]...

  7. Java:Maven依赖包下载 – 程序员最后都要送外卖

    Java:Maven依赖包下载 Maven依赖的包可以到Maven的中心仓库 http://search.ma […]...

  8. VB资料库-无限下载 – 右手边

    VB资料库-无限下载 请使用网际快车或迅雷下载.不然下载不了的哦.. 无意中找到的资料.不知道对大家有没有用. […]...

随机推荐

  1. drf 认证校验及源码分析

    认证校验    认证校验是十分重要的,如用户如果不登陆就不能访问某些接口。    再比如用户不登陆就不能够对一 […]...

  2. StarUML 系列,静态图与动态图,用例图,类图  大部分:   静态图部分,即静态不动的图

    1.用例图, Use case diagram 1.展示系统核心功能及与其交互的用户ACTOR 表示:椭圆 s […]...

  3. 《代码整洁之道》读书笔记

    为了获得更好的阅读体验,请访问原文:传送门 一、前言 代码是什么呢?或者说作为程序员的我们,对于写代码这件事又 […]...

  4. 机器学习-TensorFlow应用之 binned features, Cross features和optimizer

    概述 这一节主要介绍一下TensorFlow在应用的过程中的几个小的知识点,第一个是关于features的处理 […]...

  5. 使用PowerDesigner画ER图详细教程

    http://blog.insigmaedu.com/insigmablog/?p=1262 一、概念数据模型 […]...

  6. 常用电子元器件及应用

    一、电阻器1.薄膜类(1)金属膜电阻(型号:RJ)。在陶瓷骨架表面,经真空高温或烧渗工艺蒸发沉积一层金属膜或合 […]...

  7. 全栈工程师技术学习路线图

    抱着一个学徒的心,不断的打磨自己,直到永远。 前端技术:   包括WEB端的基础开发框架、模型驱动开发框架、移 […]...

  8. Vue学习笔记

    Vue概述  Vue (读音/vju/, 类似于view)是一套用于构建用户界面的渐进式框架,发布于2014年 […]...

展开目录

目录导航