# 自定义图表组件
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/07.%20%E5%BC%80%E5%8F%91%E6%8A%80%E5%B7%A7/18.%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%9B%BE%E8%A1%A8%E7%BB%84%E4%BB%B6


# 自定义图表组件

## 柱状图

![img](https://cdn.widiazine.com/obsidian/202408272334267.png)

### 引用方式

```js
import Bar from '/@/components/chart/Bar.vue';
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

```js
[
    {
        "name": "1月",
        "value": 320
    },
    {
        "name": "2月",
        "value": 457
    },
    {
        "name": "3月",
        "value": 182
    }
]
```

### 代码示例

```js
<template>
     <Bar :chartData="chartData"></Bar>
</template>

<script lang="ts" setup>
    import Bar from '/@/components/chart/Bar.vue';
    const chartData = [
         {
             "name": "1月",
             "value": 320
         },
         {
             "name": "2月",
             "value": 457
         },
         {
             "name": "3月",
             "value": 182
         }
     ]
</script>

<style></style>
```

## 多列柱状图

![img](https://cdn.widiazine.com/obsidian/202408272334341.png)

### 引用方式

```js
import BarMulti from '/@/components/chart/BarMulti.vue';
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

```js
[
     {
         "name": "1月",
         "value": 320,
         "type": "2021"
     },
     {
         "name": "2月",
         "value": 457,
         "type": "2021"
     },
     {
         "name": "3月",
         "value": 182,
         "type": "2021"
     },
     {
          "name": "1月",
          "value": 240,
          "type": "2022"
      },
      {
          "name": "2月",
          "value": 357,
          "type": "2022"
      },
      {
          "name": "3月",
          "value": 456,
          "type": "2022"
      }
 ]
```

## 迷你柱状图

同柱形图，修改配置即可

## 面积图

![img](https://cdn.widiazine.com/obsidian/202408272334316.png)

### 引用方式

```js
import Line from '/@/components/chart/Line.vue';
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

```js
[
    {
     "name": "1月",
     "value": 320
     },
    {
     "name": "2月",
     "value": 457
    },
    {
     "name": "3月",
     "value": 182
    }
]
```

## 多行折线图

![img](https://cdn.widiazine.com/obsidian/202408272334282.png)

### 引用方式

```js
import LineMulti from '/@/components/chart/LineMulti.vue';
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

同柱形图

## 饼状图

![img](https://cdn.widiazine.com/obsidian/202408272334399.png)

### 引用方式

```js
import Pie from '/@/components/chart/Pie'
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

```js
[
    { "name": "一月", "value": 40 },
    { "name": "二月", "value": 21 },
    { "name": "三月", "value": 17 },
    { "name": "四月", "value": 13 },
    { "name": "五月", "value": 9 }
]
```

## 雷达图

![img](https://cdn.widiazine.com/obsidian/202408272334410.png)

### 引用方式

```js
import Radar from '/@/components/chart/Radar'
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明       |
| :-------- | :----- | :--- | :--------- |
| chartData | array  | ✔️    | 图表数据源 |
| width     | number |      | 图表宽度   |
| height    | number |      | 图表高度   |
| option    | object |      | 配置项     |

### chartData 示例

```js
[
{ value: 75, name: '政治',type:'文综',max:100 },
{ value: 65, name: '历史',type:'文综',max:100 },
{ value: 55, name: '地理',type:'文综',max:100 },
{ value: 74, name: '化学',type:'文综',max:100 },
{ value: 38, name: '物理',type:'文综',max:100 },
{ value: 88, name: '生物',type:'文综',max:100 },
]
```

## 仪表盘

![img](https://cdn.widiazine.com/obsidian/202408272334791.png)

### 引用方式

```js
import Gauge from '/@/components/chart/Gauge'
```

### 参数列表

| 参数名    | 类型   | 必填 | 说明         |
| :-------- | :----- | :--- | :----------- |
| chartData | array  | ✔️    | 图表数据源   |
| option    | object |      | 图表的配置项 |
| width     | string |      | 图表宽度     |
| height    | string |      | 图表高度     |

### chartData 示例

```js
{
name:'出勤率',
value:70
}
```

## 排名列表

![img](https://cdn.widiazine.com/obsidian/202408272334861.png)

### 引用方式

```js
import RankList from '@/components/chart/RankList'
```

### 参数列表

| 参数名 | 类型   | 必填 | 说明                     |
| :----- | :----- | :--- | :----------------------- |
| title  | string |      | 图表标题                 |
| list   | array  |      | 排名列表数据             |
| height | number |      | 图表高度，默认自适应高度 |

### list 示例

```js
[
    { "name": "北京朝阳 1 号店", "total": 1981 },
    { "name": "北京朝阳 2 号店", "total": 1359 },
    { "name": "北京朝阳 3 号店", "total": 1354 },
    { "name": "北京朝阳 4 号店", "total": 263 },
    { "name": "北京朝阳 5 号店", "total": 446 },
    { "name": "北京朝阳 6 号店", "total": 796 }
]
```
