echarts 自定义仪表盘设置背景图片

echarts仪表盘 使用插件 vue-echarts

代码示例

HTML部分

<v-chart ref="heartMap" class="heartMap" :option="option"></v-chart>

js部分

// 配置项
options: {
        // 背景图片设置
        graphic: [
          {
            type: "image",
            left: "0",
            top: "0",
            z: -10,
            bounding: "raw",
            rotation: 0, //旋转
            origin: [30, 55], //中心点
            scale: [0.9, 0.9], //缩放
            style: {
              // 背景图
              image: require("@/assets/images/11.png"),
              opacity: 1,
            },
          },
        ],
        series: [
          {
            type: "gauge",
            startAngle: 90,
            endAngle: -270,
            radius: "65%",
            center: [
              // 圆心
              "47%",
              "48%",
            ],
            pointer: {
              show: false,
            },
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#F86921", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#FE9E27", // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
                borderWidth: 3,
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                shadowOffsetX: 50,
                shadowOffsetY: 50,
                shadowBlur: 30,
              },
            },
            progress: {
              show: true,
              overlap: false,
              roundCap: true,
              clip: false,
              itemStyle: {
                borderWidth: 1,
              },
            },
            axisLine: {
              show: false,
            },
            splitLine: {
              show: false,
              distance: 0,
              length: 10,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: false,
              distance: 50,
            },
            data: [
              {
                value: 0,
                name: "Perfect",
                title: {
                  show: false,
                  offsetCenter: ["0%", "-30%"],
                },
              },
            ],
            detail: {
              fontSize: 20,
              color: "#FFF",
              borderColor: "auto",
              formatter: function() {
                return getischargeOptions();
              },
              offsetCenter: [5, -5],
            },
          },
        ],
      }
      // 数据格式化
      const getischargeOptions = () => {
      return Number(options.series[0].data[0].value).toFixed(2) + '%';
    };

效果图

在这里插入图片描述

### ECharts 自定义仪表盘使用教程 #### 创建基本 HTML 文件并引入 ECharts 库 为了创建一个自定义ECharts 仪表盘图表,首先需要准备一个HTML文件,并通过`<script>`标签来加载ECharts库[^1]。 ```html <!DOCTYPE html> <html style="height: 100%"> <head> <meta charset="utf-8"> </head> <body style="height: 100%; margin: 0;"> <!-- Prepare a DOM container with width and height --> <div id="main" style="height: 100%"></div> <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> <script type="text/javascript"> // Initialize the echarts instance based on the prepared dom. var myChart = echarts.init(document.getElementById('main')); // Specify chart configuration item and data var option; // ... (configuration will be added here) // Use setOption to pass in options after initialization option && myChart.setOption(option); </script> </body> </html> ``` #### 配置仪表盘选项 接下来配置仪表盘的具体样式和数据源。这里展示了一个简单的例子,在这个例子中设置了最小值、最大值以及当前指针指向的位置等参数。 ```javascript option = { series: [ { name: 'Speed', type: 'gauge', // Set as gauge type min: 0, // Minimum value of this axis max: 220, // Maximum value of this axis splitNumber: 11, radius: '75%', detail: {formatter:'{value} km/h'}, title : { offsetCenter: ['-90%', '-30%'], fontSize: 16 }, pointer: { length: '80%' }, data: [{value: 120}] // The current speed displayed by the instrument panel } ] }; ``` 上述代码片段展示了如何设置一个名为 "Speed"(速度) 的仪表盘组件,其范围是从 `0` 到 `220`, 并且默认显示的速度为 `120`. #### 添加更多定制化功能 除了基础属性外,还可以进一步调整刻度线的颜色、宽度;修改表盘背景颜色;甚至可以加入渐变效果使整个图形看起来更加美观. 例如: * 更改刻度颜色可以通过修改`axisLine.lineStyle.color` 属性实现; * 设置不同的区域不同颜色可通过增加`splitLine.show=true` 和指定多个区间段的方式完成; * 对于更复杂的视觉需求,则可能涉及到CSS动画或者其他高级特性.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值