【示功图使用echarts实现过程】

本文详细介绍了如何利用Echarts库在HTML中创建一个分所销售水量占比的示功图,包括数据点定义、图表配置和最终的代码实现过程。

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

示功图使用echarts实现过程

1.代码实现过程

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@4.1.0/dist/echarts.min.js"></script>
  </head>
  <body>
    <div id="chart" style="width: 300px; height: 200px"></div>
    <script>
      // 获取图表容器
      let chartContainer = document.getElementById("chart");

      // 初始化Echarts图表对象
      let myChart = echarts.init(chartContainer);

      // 定义曲线数据点
      const dataPoints = [
        { x: 0, y: 0 }, // 起始点
        { x: 100, y: 80 },
        { x: 200, y: 70 },
        { x: 300, y: 90 },
        { x: 400, y: 80 }, // 结束点
      ];

      const sData = [];
      for (let i = 0; i < dataPoints.length; i++) {
        let point = dataPoints[i];
        sData.push([point.x, point.y]);
      }
      sData.push([dataPoints[0].x, dataPoints[0].y]);
      // 配置选项
      let option = {
        title:{
            text:'分所销售水量占比',
            top:'0',
            left:'center',
            textStyle:{
                color:'#000',
                align:'center',
                fontSize:12,
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
               
                lineStyle: {
                    width: 0
                }
            },
            backgroundColor: 'rgba(0,0,0,0.6)',
            textStyle: {
                color: '#fff'
            },
            padding: [10, 10],
            extraCssText: 'box-shadow: 1px 0 2px 0 rgba(163,163,163,0.5)'
        }, // 提示框组件
        legend: {}, // 图例组件
        grid: { left: "0", top: "20", bottom: "0", containLabel: true }, // 网格布局
        xAxis: {
          show: true,
          axisLine: {
            lineStyle: {
              color: "#DCE2E8",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            interval: 0,
            textStyle: {
              color: "#999",
            },
            fontSize: 12,
            margin: 5,
          },
        }, // X轴
        yAxis: {
          show: true,
          axisLine: {
            lineStyle: {
              color: "#DCE2E8",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            interval: 0,
            textStyle: {
              color: "#999",
            },
            fontSize: 12,
            margin: 5,
          },
        }, // Y轴
        series: [
          {
            type: "line",
            smooth: true, // 平滑曲线效果
            symbolSize: 0, // 不显示标记点
            lineStyle: { width: 1, color: "#FFA500" }, // 线条样式
            //itemStyle: { color: "#FFA500" }, // 项目样式(曲线颜色)
            data: sData,
          },
        ],
      };
      // 使用配置项生成图表
      myChart.setOption(option);
    </script>
  </body>
</html>

2.代码运行效果图
在这里插入图片描述
3.便于示功图等效果的二次开发,欢迎使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值