echarts-kit:基于 ECharts 与 Vue 2 的图表组件库项目

可快速在 Vue 2 项目中集成各类图表,满足数据可视化需求。内置柱状图、折线图等多种常用组件,采用蓝绿色科技风主题,支持响应式设计与高度自定义配置,开箱即用。【此简介由AI生成】

Branch1Tags0

ECharts Kit

基于 ECharts 的 Vue 2 图表组件库,采用蓝绿色科技风主题设计。

特性

  • 🎨 深色科技风主题 - 蓝绿色渐变配色,适合数据可视化大屏
  • 📦 开箱即用 - 内置多种常用图表组件
  • 🎯 响应式设计 - 自动适应容器尺寸变化
  • 🔧 高度可配置 - 支持自定义主题、样式和配置项

安装

npm install echarts-kit
# 或
yarn add echarts-kit

快速开始

<template>
  <BarChart :data="chartData" />
</template>

<script>
import { BarChart } from 'echarts-kit'

export default {
  components: { BarChart },
  data() {
    return {
      chartData: [
        { name: '周一', value: 120 },
        { name: '周二', value: 200 },
        { name: '周三', value: 150 },
        { name: '周四', value: 180 },
        { name: '周五', value: 220 }
      ]
    }
  }
}
</script>

组件列表

组件 说明 数据格式
BarChart 柱状图 [{name, value}, ...]
LineChart 折线图 [{name, value}, ...]
PieChart 饼图 [{name, value}, ...]
ScatterChart 散点图 [{x, y}, ...]
RadarChart 雷达图 [{name, value[]}, ...] + indicator
BoxChart 箱线图 [{name, value[]}, ...]
GraphChart 关系图 {nodes: [...], links: [...]}
GaugeChart 仪表盘 {value, name}

API 文档

BarChart

属性 类型 默认值 说明
data Array [] 数据源
xKey String 'name' X轴字段名
yKey String 'value' Y轴字段名
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸
showArea Boolean false 是否显示渐变区域

入参实例:

<template>
  <BarChart 
    :data="barData" 
    :colors="['#00d4ff', '#00ff9d']"
    height="400px"
    :showArea="true"
  />
</template>

<script>
import { BarChart } from 'echarts-kit'

export default {
  components: { BarChart },
  data() {
    return {
      barData: [
        { name: '周一', value: 120 },
        { name: '周二', value: 200 },
        { name: '周三', value: 150 },
        { name: '周四', value: 180 },
        { name: '周五', value: 220 },
        { name: '周六', value: 190 },
        { name: '周日', value: 210 }
      ]
    }
  }
}
</script>

LineChart

属性 类型 默认值 说明
data Array [] 数据源
xKey String 'name' X轴字段名
yKey String 'value' Y轴字段名
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸
showArea Boolean false 是否显示渐变区域
smooth Boolean true 是否平滑曲线

入参实例:

<template>
  <LineChart 
    :data="lineData" 
    :smooth="false"
    :showArea="true"
  />
</template>

<script>
import { LineChart } from 'echarts-kit'

export default {
  components: { LineChart },
  data() {
    return {
      lineData: [
        { name: '1月', value: 100 },
        { name: '2月', value: 150 },
        { name: '3月', value: 130 },
        { name: '4月', value: 180 },
        { name: '5月', value: 200 },
        { name: '6月', value: 220 }
      ]
    }
  }
}
</script>

PieChart

属性 类型 默认值 说明
data Array [] 数据源
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸

入参实例:

<template>
  <PieChart 
    :data="pieData" 
    :colors="['#00d4ff', '#00ff9d', '#0ea5e9', '#22d3ee', '#4ade80']"
  />
</template>

<script>
import { PieChart } from 'echarts-kit'

export default {
  components: { PieChart },
  data() {
    return {
      pieData: [
        { value: 335, name: '直接访问' },
        { value: 278, name: '邮件营销' },
        { value: 189, name: '联盟广告' },
        { value: 150, name: '视频广告' },
        { value: 120, name: '搜索引擎' }
      ]
    }
  }
}
</script>

ScatterChart

属性 类型 默认值 说明
data Array [] 数据源
xKey String 'x' X轴字段名
yKey String 'y' Y轴字段名
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸
symbolSize Number/Function 10 标记大小

入参实例:

<template>
  <ScatterChart 
    :data="scatterData" 
    :symbolSize="15"
  />
</template>

<script>
import { ScatterChart } from 'echarts-kit'

export default {
  components: { ScatterChart },
  data() {
    return {
      scatterData: [
        { x: 10.0, y: 8.04 },
        { x: 8.07, y: 6.95 },
        { x: 13.0, y: 7.58 },
        { x: 9.05, y: 8.81 },
        { x: 11.0, y: 8.33 },
        { x: 14.0, y: 9.96 },
        { x: 13.4, y: 8.10 },
        { x: 10.0, y: 6.13 },
        { x: 14.0, y: 9.15 },
        { x: 12.5, y: 7.22 }
      ]
    }
  }
}
</script>

RadarChart

属性 类型 默认值 说明
data Array [] 数据源
indicator Array [] 指示器配置
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸
shape String 'polygon' 形状(polygon/circle)
areaStyle Boolean/Object true 区域样式

入参实例:

<template>
  <RadarChart 
    :data="radarData" 
    :indicator="radarIndicator"
    shape="circle"
  />
</template>

<script>
import { RadarChart } from 'echarts-kit'

export default {
  components: { RadarChart },
  data() {
    return {
      radarData: [
        { name: '预算分配', value: [4300, 10000, 28000, 35000, 50000, 19000] },
        { name: '实际开销', value: [5000, 14000, 28000, 31000, 42000, 21000] }
      ],
      radarIndicator: [
        { name: '销售', max: 65000 },
        { name: '管理', max: 160000 },
        { name: '技术', max: 380000 },
        { name: '客服', max: 450000 },
        { name: '研发', max: 520000 },
        { name: '市场', max: 250000 }
      ]
    }
  }
}
</script>

BoxChart

属性 类型 默认值 说明
data Array [] 数据源
xKey String 'name' X轴字段名
yKey String 'value' Y轴字段名
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '350px' 高度
autoresize Boolean true 自动调整尺寸

入参实例:

<template>
  <BoxChart :data="boxData" />
</template>

<script>
import { BoxChart } from 'echarts-kit'

export default {
  components: { BoxChart },
  data() {
    return {
      boxData: [
        { name: '商品A', value: [76, 85, 93, 98, 105, 110, 115] },
        { name: '商品B', value: [65, 72, 80, 88, 95, 102, 108] },
        { name: '商品C', value: [80, 88, 95, 102, 110, 118, 125] }
      ]
    }
  }
}
</script>

GraphChart

属性 类型 默认值 说明
data Object {nodes:[], links:[]} 数据源(包含nodes和links)
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '400px' 高度
autoresize Boolean true 自动调整尺寸
layout String 'force' 布局方式
roam Boolean true 是否允许缩放拖拽
draggable Boolean true 是否允许节点拖拽
symbolSize Number/Function 20 节点大小
lineStyle Object null 连接线样式
label Boolean/Object true 标签配置

入参实例:

<template>
  <GraphChart :data="graphData" height="500px" />
</template>

<script>
import { GraphChart } from 'echarts-kit'

export default {
  components: { GraphChart },
  data() {
    return {
      graphData: {
        nodes: [
          { name: '核心服务', symbolSize: 40, description: '核心业务服务' },
          { name: '用户管理', symbolSize: 30 },
          { name: '订单系统', symbolSize: 30 },
          { name: '支付服务', symbolSize: 30 },
          { name: '数据分析', symbolSize: 30 },
          { name: '消息队列', symbolSize: 25 },
          { name: '数据库', symbolSize: 25 },
          { name: '缓存层', symbolSize: 25 },
          { name: 'API网关', symbolSize: 25 }
        ],
        links: [
          { source: 'API网关', target: '核心服务', value: 10 },
          { source: '核心服务', target: '用户管理', value: 8 },
          { source: '核心服务', target: '订单系统', value: 8 },
          { source: '核心服务', target: '支付服务', value: 8 },
          { source: '核心服务', target: '数据分析', value: 6 },
          { source: '订单系统', target: '数据库', value: 10 },
          { source: '用户管理', target: '数据库', value: 10 },
          { source: '核心服务', target: '消息队列', value: 6 },
          { source: '数据分析', target: '消息队列', value: 6 },
          { source: '核心服务', target: '缓存层', value: 6 }
        ]
      }
    }
  }
}
</script>

GaugeChart

属性 类型 默认值 说明
data Object {value: 0, name: '指标'} 数据源(包含value和name)
colors Array null 自定义颜色数组
width String '100%' 宽度
height String '250px' 高度
autoresize Boolean true 自动调整尺寸
min Number 0 最小值
max Number 100 最大值
splitNumber Number 10 刻度分割数
startAngle Number 200 开始角度
endAngle Number -20 结束角度
pointer Object null 指针样式配置
axisLine Object null 轴线样式配置
detail Object null 详情配置
title Object null 标题配置

入参实例:

<template>
  <div class="gauge-container">
    <GaugeChart :data="gaugeData1" height="280px" />
    <GaugeChart :data="gaugeData2" height="280px" />
    <GaugeChart :data="gaugeData3" height="280px" />
  </div>
</template>

<script>
import { GaugeChart } from 'echarts-kit'

export default {
  components: { GaugeChart },
  data() {
    return {
      gaugeData1: { value: 75, name: 'CPU使用率' },
      gaugeData2: { value: 82, name: '内存使用率' },
      gaugeData3: { value: 65, name: '网络流量' }
    }
  }
}
</script>

<style scoped>
.gauge-container {
  display: flex;
  justify-content: space-around;
}
</style>

事件

所有图表组件支持以下事件:

事件 参数 说明
click params 点击图表时触发
ready chartInstance 图表初始化完成时触发

方法

所有图表组件支持以下方法:

方法 说明
getInstance() 获取 ECharts 实例
dispatchAction(payload) 触发图表行为

主题配置

默认主题采用深色科技风格:

// 默认颜色
colors: ['#00d4ff', '#00ff9d', '#0ea5e9', '#22d3ee', '#4ade80', '#06b6d4', '#10b981', '#14b8a6']

// 背景色
backgroundColor: '#0a1628'

// 文字颜色
textColor: '#e2e8f0'
subTextColor: '#94a3b8'

开发

# 安装依赖
npm install

# 开发模式
npm run build:watch

# 生产构建
npm run build

项目结构

echarts-kit/
├── src/
│   ├── components/
│   │   ├── charts/          # 图表组件
│   │   │   ├── BarChart.vue
│   │   │   ├── LineChart.vue
│   │   │   ├── PieChart.vue
│   │   │   ├── ScatterChart.vue
│   │   │   ├── RadarChart.vue
│   │   │   ├── BoxChart.vue
│   │   │   └── index.js
│   │   ├── core/            # 核心组件
│   │   │   └── EchartsCore.vue
│   │   └── index.js
│   ├── theme/               # 主题配置
│   │   ├── colors.js
│   │   ├── grid.js
│   │   └── index.js
│   ├── utils/               # 工具函数
│   │   └── dataProcessor.js
│   └── index.js             # 入口文件
├── dist/                    # 构建产物
├── package.json
├── rollup.config.js
└── README.md

许可证

MIT

Introduction

可快速在 Vue 2 项目中集成各类图表,满足数据可视化需求。内置柱状图、折线图等多种常用组件,采用蓝绿色科技风主题,支持响应式设计与高度自定义配置,开箱即用。【此简介由AI生成】

Customize your domain