Echarts-绘制生命周期图

文章描述了一个项目需求,要求点击按钮后弹出对话框显示生命周期图。通过Vue组件和Echarts插件,实现数据驱动的动态图表,颜色根据状态变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录


需求

项目点击一个按钮后弹出框展示生命周期图


实现

利用Echarts插件

  1. 点击弹出框。生命周期页面在新的页面“lifeCycle.vue”编写,点击弹出框后引用此页面,引用代码如下:
<template>
 	<el-button type="text" icon="fa fa-circle-notch" @click="lifeCycleClick(val)" circle></el-button>
 	...
	<lifeCycle v-if="dialogLifeCycle" ref="lifeCycle"></lifeCycle>
	...
</template>
<script>
import lifeCycle from './LifeCycle'
export default {
	...
	components: {lifeCycle},
	data:function(){
		...
	},
	methods:{
	lifeCycleClick(val){
        this.dialogLifeCycle=true;
         this.$nextTick(() => {
             this.$refs.lifeCycle.init1(val);
         });
     },
   }
	...
}
</script>
  1. 生命周期页面lifeCycle.vue
    代码如下,借用vue中使用echarts画一个生命周期图
<template>
    <el-dialog
        :title="title"
        :visible.sync="dialogVisible"
        width="50%" custom-class='dialog'>
        <div ref="box"  class="box"></div>
    </el-dialog>
</template>
<script>
import * as echarts from 'echarts'

method代码

init1(val) {
     var Vuethis=this;
     this.dialogVisible=true,
     this.$nextTick(() => { 
         Vuethis.initEcharts(this.data);
     })
  },
initEcharts(data){
	var myChart = echarts.init(this.$refs.box)
	myChart.clear();
   	myChart.setOption({
       title: {
           text: '产品生命周期',
       },
       animationDurationUpdate: 1500,
       animationEasingUpdate: 'quinticInOut',
       legend: [
           {
               height: 10,
               left: 'center',
               itemGap: 15,
               textStyle: {
                   color: (params) => params,
                   fontSize: 13,
               },
           },
       ],
       color: ['#fc853e', '#28cad8', '#9564bf', '#bd407e', '#28cad8', '#e5a214'],
       series: [
           {
               type: 'graph',
               layout: 'none',
               symbolSize: 50,
               roam: false, // false禁止放大缩小拖拽
               label: {
                   show: true,
               },
               edgeSymbolSize: [0, 10],
               edgeLabel: {
                   fontSize: 20,
               },
               data: [
                   {
                       // name: '1 \n 已报备',
                       name: '1', // 球内的文字
                       x: 275, // 球X轴的位置
                       y: 0, // // 球Y轴的位置
                       itemStyle: {
                           normal: {
                               borderColor: '#3E8EF7', // 球内的边框颜色
                               borderWidth: 15, // 球的大小
                               color: '#3E8EF7', // 球的颜色
                           },
                       },
                       label: {
                           fontSize: 12, // 球内文字大小
                           color: '#fff', // 球内文字颜色
                       },
                   },
                   {
                       // name: '2',
                       name: '2',
                       x: 288,
                       y: 7,
                       // legend: {},
                       itemStyle: {
                           // 各圆圈自定义样式
                           normal: {
                               borderColor: this.active >= 2 ? '#3E8EF7' : '#ccc',  // 判断,当active大于或者等于2时,球内的边框颜色为#3E8EF7,否则颜色为#ccc
                               borderWidth: 15,
                               // shadowBlur: 20,
                               shadowColor: '#ccc',
                               color: this.active >= 2 ? '#3E8EF7' : '#ccc', // 判断,当active大于或者等于2时,球的颜色为#3E8EF7,否则颜色为#ccc
                               //  color: this.active == '验证中' ? '#3E8EF7':'#ccc',
                               //  color: this.active == '验证失败' ? '#3E8EF7':'#ccc',
                           },
                       },
                       label: {
                           fontSize: 12,
                           fontWeight: 600,
                           color: '#fff',
                           // formatter:function(params){
                           //   console.log(params,'params')
                           //   return `<div>111</div>`+params;
                           // }
                       },
                   },
                   {
                       // name: '3',
                       name:'3',
                       // x: 0,
                       // y: 200,
                       x:288,
                       y:20,
                       itemStyle: {
                           // 各圆圈自定义样式
                           normal: {
                               borderColor: this.active >= 3 ? '#3E8EF7' : '#ccc',
                               borderWidth: 15,
                               // shadowBlur: 20,
                               shadowColor: this.active >= 3 ? '#3E8EF7' : '#ccc',
                               // color: new echarts.graphic.RadialGradient(0.5, 0.5, 1.0),
                               color: this.active >= 3 ? '#3E8EF7' : '#ccc',
                           },
                       },
                       label: {
                           fontSize: 12,
                           fontWeight: 600,
                           color: '#fff',
                       },
                   },
                   {
                       // name: '4',
                       name:'4',
                       x: 275,
                       y: 28,
                       itemStyle: {
                           // 各圆圈自定义样式
                           normal: {
                               borderColor: this.active >= 4 ? '#3E8EF7' : '#ccc',
                               borderWidth: 15,
                               // shadowBlur: 20,
                               shadowColor: this.active >= 4 ? '#3E8EF7' : '#ccc',
                               // color: new echarts.graphic.RadialGradient(0.5, 0.5, 1.0),
                               color: this.active >= 4 ? '#3E8EF7' : '#ccc',
                           },
                       },
                       label: {
                           fontSize: 12,
                           fontWeight: 600,
                           color: '#fff',
                       },
                   },
                   {
                       // name: '5',
                       name:'5',
                       x: 262,
                       y: 20,
                       itemStyle: {
                           // 各圆圈自定义样式
                           normal: {
                               borderColor: this.active >= 5 ? '#3E8EF7' : '#ccc',
                               borderWidth: 15,
                               // shadowBlur: 20,
                               shadowColor: this.active >= 5 ? '#3E8EF7' : '#ccc',
                               color: this.active >= 5 ? '#3E8EF7' : '#ccc',
                           },
                       },
                       label: {
                           fontSize: 12,
                           fontWeight: 600,
                           color: '#fff',
                       },
                   },
                   {
                       // name: '6',
                       name:'6',
                       x: 262,
                       y: 7,
                       itemStyle: {
                           // 各圆圈自定义样式
                           normal: {
                               borderColor: this.active >= 6 ? '#3E8EF7' : '#ccc',
                               borderWidth: 15,
                               // shadowBlur: 20,
                               shadowColor: this.active >= 6 ? '#3E8EF7' : '#ccc',
                               color: this.active >= 6 ? '#3E8EF7' : '#ccc',
                           },
                       },
                       label: {
                           fontSize: 12,
                           fontWeight: 600,
                           color: '#fff',
                       },
                   },
               ],
               // links: [],
               links: [ // links自定义线
                   // 1-2 1到2的位置的线
                   {
                       source: 0,
                       target: 1,
                       symbolSize: [20, 20], // 线的大小
                       symbol: ['', 'arrow'], // 线加箭头,两个为arrow,则是双箭头
                       label: {
                           // show: true
                       },
                       lineStyle: {
                       // 线的颜色,判断active为2时,线的颜色为#3E8EF7,否则为#ccc
                           color: this.active >= 2 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       // 2-3 ,2到3的位置的线
                       source: 1,
                       target: 2,
                       symbolSize: [10, 20],
                       symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 3 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       // source: 2,
                       // target: 0,
                       // symbolSize: [0, 10],
                       // symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 3 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       source: 2,
                       target: 3,
                       symbolSize: [0, 20],
                       symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 4 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       // source: 3,
                       // target: 0,
                       // symbolSize: [0, 10],
                       // symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 4 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       source: 3,
                       target: 4,
                       symbolSize: [0, 20],
                       symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 5 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       // source: 4,
                       // target: 0,
                       // symbolSize: [0, 10],
                       // symbol: ['', 'arrow'],
                       lineStyle: {
                           color: this.active >= 5 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       // 5-6的线
                       source: 4,
                       target: 5,
                       symbolSize: [0, 20],
                       symbol: ['', 'arrow'],
                       lineStyle: {
                           // width:10,
                           curveness: 0.2,
                           color: this.active >= 6 ? '#3E8EF7' : '#ccc',
                       },
                   },
                   {
                       source: 5,
                       target: 0,
                       // symbol: ['', 'arrow'],
                       // symbolSize: [0, 10],
                       lineStyle: {
                           // width: 3,
                           // curveness: 0
                           // width:10,
                           curveness: 0.2,
                           color: this.active >= 6 ? '#3E8EF7' : '#ccc',
                       },
                   },
               ],
               lineStyle: {
                   opacity: 0.8,
                   width: 10,
                   curveness: 0.2,
                   color: '#3E8EF7',
               },
           },
       ],
   })
   // 让echarts自适应
   window.addEventListener("resize", function () {
        myChart.resize();
    });
}

其他代码暂不列出。

效果

这里的效果是项目中实现的效果,与所展示的代码不同,此效果代码暂不展示。
在这里插入图片描述

要在Vue项目中使用echarts-wordcloud绘制词云图,可以按照以下步骤操作: 1. 安装echartsecharts-wordcloud插件 ```bash npm install echarts --save npm install echarts-wordcloud --save ``` 2. 在需要使用词云图的组件中引入echarts ```javascript import echarts from 'echarts' ``` 3. 在mounted生命周期中初始化echarts实例,并设置词云图的配置项 ```javascript mounted() { const chartDom = this.$refs.chart const myChart = echarts.init(chartDom) const option = { series: [{ type: 'wordCloud', shape: 'circle', sizeRange: [20, 80], rotationRange: [-90, 90], rotationStep: 45, gridSize: 2, textStyle: { normal: { fontFamily: 'sans-serif', fontWeight: 'bold', color: function () { return 'rgb(' + [ Math.round(Math.random() * 255), Math.round(Math.random() * 255), Math.round(Math.random() * 255) ].join(',') + ')' } } }, data: [ { name: 'Apple', value: 10000 }, { name: 'Banana', value: 6181 }, { name: 'Orange', value: 4386 }, { name: 'Watermelon', value: 4055 }, { name: 'Pineapple', value: 2467 }, { name: 'Grape', value: 2244 }, { name: 'Mango', value: 1898 }, { name: 'Pear', value: 1484 }, { name: 'Cherry', value: 1001 }, { name: 'Peach', value: 987 }, { name: 'Kiwi', value: 900 } ] }] } myChart.setOption(option) } ``` 4. 在模板中添加echarts实例的容器 ```html <template> <div> <div ref="chart" style="width: 600px; height: 400px;"></div> </div> </template> ``` 以上就是在Vue项目中使用echarts-wordcloud绘制词云图的步骤,需要注意的是,词云图的配置项需要根据实际需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值