在vue中使用eachers做雷达图

效果图

安装

npm i echarts

 页面引入

var echarts = require('echarts');

页面使用

<div id="customEchart" style="width:500px;height: 420px;"></div>

js配置数据方法

let customEchart = echarts.init(document.getElementById('customEchart'));//获取DOM节点
      //雷达图配置
      let customOption = {
        legend: {//图例位置
          top: "1%",
          itemWidth: 20,
          itemHeight: 12
        },
        tooltip: {//悬浮框配置
          formatter: function () {
            let str ="<table style='border-collapse:collapse;'>"+
              "<tr style='background: rgb(241, 245, 255)'>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>指标名称</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>目标</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>实际</td>"+
              "</tr>"+
              "<tr style='background: #FFF'>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>测试1</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>100</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>68</td>"+
              "</tr>"+
              "<tr style='background: #FAFAFA'>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>测试2</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>100</td>"+
                  "<td style='text-align: center;width:150px;height:30px;font-weight: 600;'>96</td>"+
              "</tr>"
            str= str + "</table>"
            return str
          }
        },
        radar: {
          name: {
            textStyle: {//字体大小颜色设置
              color: '#444',
              fontSize: 11
            },
            formatter: function (text) {//文字过长换行
              let strLength = text.length;
              if (strLength % 3 == 1) {
                text = text.replace(/\S{3}/g, function (match) {
                  return match + '\n';
                })
              } else {
                text = text.replace(/\S{3}/g, function (match) {
                  return match + '\n';
                })
                strLength = text.length;
                text = text.substring(0, strLength - 1);
              }
              return text;
            },
          },
          indicator: [{max:100,text:'测试1'},{max:100,text:'测试2'},{max:100,text:'测试3'},{max:100,text:'测试4'},{max:100,text:'测试5'},{max:100,text:'测试6'},{max:100,text:'测试7'},{max:100,text:'测试8'}],//数据维度和最大值
          center: ['50%', '50%'],
          radius: 146,
          startAngle: 96,
          splitNumber: 4,
          shape: 'circle',
        },
        series: [
          {
            name: '雷达图',
            type: 'radar',
            emphasis: {
              label: {
                show: true,
                color: '#fff',
                fontSize: 10,
                formatter: '{c}',       // 鼠标悬浮时展示数据加上单位
                backgroundColor: '#0D1B42',
                borderRadius: 5,
                padding: 3,
                shadowBlur: 3
              }
              },
            data: [{
              value: ['83.20', '93.10', '96.40', '92.10', '94.55', '89.70', '98.40', '99.10'],//实际数据
              lineStyle: {
                type: 'dashed'
              },
              areaStyle: {
                opacity: 0.1
              },
              label: {
                normal: {
                  show: true
                }
              }
            },
            ]
          },
        ]
      };
      customEchart.setOption(customOption);
      customEchart.resize();

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue使用ECharts绘制雷达图,首先需要安装ECharts库并引入到Vue项目。以下是基本步骤: 1. 安装依赖: 使用npm或yarn添加ECharts: ```bash npm install echarts @vue/echarts --save # 或者 yarn add echarts @vue/echarts ``` 2. 引入并在Vue组件使用: 在`main.js`或`.vue`文件的`<template>`标签内导入ECharts和相关的插件,如雷达图插件: ```html <script src="path/to/echarts.min.js"></script> <script src="path/to/vue-echarts.min.js"></script> ``` 3. 创建Vue实例并配置ECharts: 在`.vue`组件的`<script>`部分创建一个新的Vue实例,并将ECharts作为props传递,然后在`mounted`生命周期钩子初始化图表: ```js export default { props: ['options'], data() { return { chartInstance: null, }; }, mounted() { this.chartInstance = this.$echarts.init(this.$refs.chart); // 绘制雷达图 this.drawRadarChart(); }, methods: { drawRadarChart() { const radarOption = { // 雷达图配置项... }; this.chartInstance.setOption(radarOption); }, }, beforeDestroy() { if (this.chartInstance) { this.chartInstance.dispose(); // 销毁图表以释放资源 } }, }; ``` 4. 在模板引用图表容器: ```html <div ref="chart" style="width: 600px;height:400px;"></div> ``` 5. 使用`v-bind`绑定数据到图表: ```html <v-chart :options="options"></v-chart> ``` 现在你可以根据需要提供自定义的`options`对象来设置雷达图的数据和样式。例如: ```js // 示例雷达图配置 const radarOptions = { series: [ { type: 'radar', name: '雷达图名称', data: [ { value: [5, 2, 3, 4, 5, 2] }, // 数据点对应的值 ], // ...其他配置项 }, ], }; ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值