diff --git a/src/components/Echart/LineChart.vue b/src/components/Echart/LineChart.vue index b7ec0cc..3fec782 100644 --- a/src/components/Echart/LineChart.vue +++ b/src/components/Echart/LineChart.vue @@ -8,41 +8,85 @@ import tdTheme from './theme.json' // 引入默认主题 import { formatColor, getAlphaColor } from './utils' const props = defineProps({ - // id + /** + * id + */ id: { type: String, default: 'chart', }, + /** + * 加载状态 + */ loading: { type: Boolean, default: false, }, - // 图例是否显示 - legendShow: { - type: Boolean, - default: true, + /** + * 网格配置 + */ + grid: { + type: Object, + default: () => { + return { + top: 50, + left: 10, + right: 20, + bottom: 5, + containLabel: true, // 是否包含坐标轴的刻度标签 + } + }, }, - // 图例 + /** + * 图例设置对象 + */ legend: { + type: Object, + default: () => { + return { + show: true, + icon: 'circle', + orient: 'vertile', // 图例方向 + align: 'left', // 图例标记和文本的对齐,默认自动 + top: 0, + right: 20, + itemWidth: 12, + itemHeight: 12, + padding: [0, 0, 0, 120], + } + }, + }, + /** + * 图例列表,非必传 + */ + legendData: { type: Array, default: () => { return [] }, }, - // 图表宽 + /** + * 图表宽 + */ width: { type: String, default: '100%', }, - // 图表高 + /** + * 图表高 + */ height: { type: String, default: '100%', }, - // X轴数据 + /** + * X轴刻度数据,格式为['周一','周二'...] + */ xAxisData: { type: Array, default: () => { return [] }, }, - // X轴类型 + /** + * X轴类型 + */ xAxisType: { type: String, default: 'category', @@ -50,47 +94,75 @@ return ['category', 'value', 'time', 'log'].includes(value) }, }, - // 数据 + /** + * 数据,格式为[{name:'系列名',data:[0,0,0,...0], color:'可选'},...] + */ data: { type: Array, default: () => { return [] }, }, - // 单位 + /** + * 单位 + */ unit: { type: String, default: '', }, - // 颜色 + /** + * 颜色 + */ colors: { type: Array, - default: () => { return [] }, + default: () => { + return [ + '#2d8cf0', + '#19be6b', + '#ff9900', + '#E46CBB', + '#9A66E4', + '#ed3f14', + '#01C2F9', + ] + }, }, - // 实虚线 + /** + * 实虚线 + */ axisLineType: { type: String, default: '', }, - // 轴线颜色 + /** + * 轴线颜色 + */ axisLineColor: { type: String, default: '#96989b', }, - // 轴线上文字颜色 + /** + * 轴线上文字颜色 + */ fontColor: { type: String, default: '#000000', }, - // 是否为渐变折线图 + /** + * 是否为渐变折线图 + */ gradient: { type: Boolean, default: true, }, - // 标题 + /** + * 标题 + */ title: { type: String, default: '', }, - // 平滑 + /** + * 平滑 + */ smooth: { type: Boolean, default: true, @@ -114,25 +186,8 @@ // 构建option function buildOption() { const option: lineOption = { - grid: { - show: false, // 是否显示直角坐标系网格 - left: 10, - right: 20, - bottom: 5, - top: 50, - containLabel: true, // grid 区域是否包含坐标轴的刻度标签 - }, // 网格 - legend: { - show: props.legendShow, - icon: 'circle', - orient: 'vertile', // 图例方向 - align: 'left', // 图例标记和文本的对齐,默认自动 - top: 0, - itemWidth: 12, - itemHeight: 12, - padding: [0, 0, 0, 120], - right: 20, - }, // 图例 + grid: props.grid, + legend: props.legend, // 图例 tooltip: { trigger: 'axis', textStyle: { @@ -205,8 +260,8 @@ } } // 图例 - if (props.legend && props.legend.length > 0) { - option.legend!.data = props.legend + if (props.legend && props.legendData.length > 0) { + option.legend!.data = props.legendData } // x轴数据 if (props.xAxisData && props.xAxisData.length > 0) { diff --git a/src/components/Echart/LineChart.vue b/src/components/Echart/LineChart.vue index b7ec0cc..3fec782 100644 --- a/src/components/Echart/LineChart.vue +++ b/src/components/Echart/LineChart.vue @@ -8,41 +8,85 @@ import tdTheme from './theme.json' // 引入默认主题 import { formatColor, getAlphaColor } from './utils' const props = defineProps({ - // id + /** + * id + */ id: { type: String, default: 'chart', }, + /** + * 加载状态 + */ loading: { type: Boolean, default: false, }, - // 图例是否显示 - legendShow: { - type: Boolean, - default: true, + /** + * 网格配置 + */ + grid: { + type: Object, + default: () => { + return { + top: 50, + left: 10, + right: 20, + bottom: 5, + containLabel: true, // 是否包含坐标轴的刻度标签 + } + }, }, - // 图例 + /** + * 图例设置对象 + */ legend: { + type: Object, + default: () => { + return { + show: true, + icon: 'circle', + orient: 'vertile', // 图例方向 + align: 'left', // 图例标记和文本的对齐,默认自动 + top: 0, + right: 20, + itemWidth: 12, + itemHeight: 12, + padding: [0, 0, 0, 120], + } + }, + }, + /** + * 图例列表,非必传 + */ + legendData: { type: Array, default: () => { return [] }, }, - // 图表宽 + /** + * 图表宽 + */ width: { type: String, default: '100%', }, - // 图表高 + /** + * 图表高 + */ height: { type: String, default: '100%', }, - // X轴数据 + /** + * X轴刻度数据,格式为['周一','周二'...] + */ xAxisData: { type: Array, default: () => { return [] }, }, - // X轴类型 + /** + * X轴类型 + */ xAxisType: { type: String, default: 'category', @@ -50,47 +94,75 @@ return ['category', 'value', 'time', 'log'].includes(value) }, }, - // 数据 + /** + * 数据,格式为[{name:'系列名',data:[0,0,0,...0], color:'可选'},...] + */ data: { type: Array, default: () => { return [] }, }, - // 单位 + /** + * 单位 + */ unit: { type: String, default: '', }, - // 颜色 + /** + * 颜色 + */ colors: { type: Array, - default: () => { return [] }, + default: () => { + return [ + '#2d8cf0', + '#19be6b', + '#ff9900', + '#E46CBB', + '#9A66E4', + '#ed3f14', + '#01C2F9', + ] + }, }, - // 实虚线 + /** + * 实虚线 + */ axisLineType: { type: String, default: '', }, - // 轴线颜色 + /** + * 轴线颜色 + */ axisLineColor: { type: String, default: '#96989b', }, - // 轴线上文字颜色 + /** + * 轴线上文字颜色 + */ fontColor: { type: String, default: '#000000', }, - // 是否为渐变折线图 + /** + * 是否为渐变折线图 + */ gradient: { type: Boolean, default: true, }, - // 标题 + /** + * 标题 + */ title: { type: String, default: '', }, - // 平滑 + /** + * 平滑 + */ smooth: { type: Boolean, default: true, @@ -114,25 +186,8 @@ // 构建option function buildOption() { const option: lineOption = { - grid: { - show: false, // 是否显示直角坐标系网格 - left: 10, - right: 20, - bottom: 5, - top: 50, - containLabel: true, // grid 区域是否包含坐标轴的刻度标签 - }, // 网格 - legend: { - show: props.legendShow, - icon: 'circle', - orient: 'vertile', // 图例方向 - align: 'left', // 图例标记和文本的对齐,默认自动 - top: 0, - itemWidth: 12, - itemHeight: 12, - padding: [0, 0, 0, 120], - right: 20, - }, // 图例 + grid: props.grid, + legend: props.legend, // 图例 tooltip: { trigger: 'axis', textStyle: { @@ -205,8 +260,8 @@ } } // 图例 - if (props.legend && props.legend.length > 0) { - option.legend!.data = props.legend + if (props.legend && props.legendData.length > 0) { + option.legend!.data = props.legendData } // x轴数据 if (props.xAxisData && props.xAxisData.length > 0) { diff --git a/src/components/Echart/PieChart.vue b/src/components/Echart/PieChart.vue index 797fd58..032ee81 100644 --- a/src/components/Echart/PieChart.vue +++ b/src/components/Echart/PieChart.vue @@ -9,21 +9,30 @@ import tdTheme from './theme.json' // 引入默认主题 import { formatColor, getAlphaColor } from './utils' const props = defineProps({ - // id + /** + * id + */ id: { type: String, default: 'chart', }, + /** + * 加载中 + */ loading: { type: Boolean, default: false, }, - // 标题 + /** + * 标题 + */ title: { type: String, default: '', }, - // 图例是否显示 + /** + * 图例是否显示 + */ legend: { type: Object, default: () => { @@ -41,47 +50,67 @@ } }, }, - // 文本标签是否显示 + /** + * 文本标签是否显示 + */ labelShow: { type: Boolean, default: true, }, - // 图表宽 + /** + * 图表宽 + */ width: { type: String, default: '100%', }, - // 图表高 + /** + * 图表高 + */ height: { type: String, default: '100%', }, - // 饼图的半径[内半径,外半径] + /** + * 饼图的半径[内半径,外半径] + */ radius: { type: Array, default: () => { return ['30%', '45%'] }, }, - // 是否要展示成玫瑰图,或玫瑰图类型:radius|area + /** + * 是否要展示成玫瑰图,或玫瑰图类型:radius|area + */ roseType: { type: [String, Boolean], default: false, }, - valueType: { // 显示值类型:percentage百分比|value数值 + /** + * 显示值类型:percentage百分比|value数值 + */ + valueType: { type: String, default: 'percentage', }, - // 数据 + /** + * 数据,格式为 [{name:'xxx',value:0},...] + */ data: { type: Array, default: () => { return [] }, }, - // 颜色 + /** + * 颜色 + */ colors: { type: Array, default: () => { return ['#3d7eff', '#caddff'] }, }, + /** + * 网格配置 + */ grid: { type: Object, default: () => { @@ -94,15 +123,30 @@ } }, }, - // 标签文字颜色 + /** + * 标签文字颜色 + */ fontColor: { type: String, default: '#000000', }, + /** + * 标签格式化 + */ labelFormatter: { type: String, default: '', }, + /** + * 标签位置, outside饼图扇区外侧, inside饼图扇区内部, center饼图中心位置 + */ + labelPosition: { + type: String, + default: 'center', + }, + /** + * 悬停格式化 + */ hoverFormatter: { type: String, default: '{b}
数量:{c}
占比:{d}%', @@ -127,14 +171,7 @@ // 构建option function buildOption() { const option: pieOption = { - grid: { - show: false, // 是否显示直角坐标系网格 - left: props.grid.left, - right: props.grid.right, - bottom: props.grid.bottom, - top: props.grid.top, - containLabel: props.grid.containLabel, // grid 区域是否包含坐标轴的刻度标签 - }, // 网格 + grid: props.grid, // 网格 legend: props.legend, // 图例 tooltip: { show: true, diff --git a/src/components/Echart/LineChart.vue b/src/components/Echart/LineChart.vue index b7ec0cc..3fec782 100644 --- a/src/components/Echart/LineChart.vue +++ b/src/components/Echart/LineChart.vue @@ -8,41 +8,85 @@ import tdTheme from './theme.json' // 引入默认主题 import { formatColor, getAlphaColor } from './utils' const props = defineProps({ - // id + /** + * id + */ id: { type: String, default: 'chart', }, + /** + * 加载状态 + */ loading: { type: Boolean, default: false, }, - // 图例是否显示 - legendShow: { - type: Boolean, - default: true, + /** + * 网格配置 + */ + grid: { + type: Object, + default: () => { + return { + top: 50, + left: 10, + right: 20, + bottom: 5, + containLabel: true, // 是否包含坐标轴的刻度标签 + } + }, }, - // 图例 + /** + * 图例设置对象 + */ legend: { + type: Object, + default: () => { + return { + show: true, + icon: 'circle', + orient: 'vertile', // 图例方向 + align: 'left', // 图例标记和文本的对齐,默认自动 + top: 0, + right: 20, + itemWidth: 12, + itemHeight: 12, + padding: [0, 0, 0, 120], + } + }, + }, + /** + * 图例列表,非必传 + */ + legendData: { type: Array, default: () => { return [] }, }, - // 图表宽 + /** + * 图表宽 + */ width: { type: String, default: '100%', }, - // 图表高 + /** + * 图表高 + */ height: { type: String, default: '100%', }, - // X轴数据 + /** + * X轴刻度数据,格式为['周一','周二'...] + */ xAxisData: { type: Array, default: () => { return [] }, }, - // X轴类型 + /** + * X轴类型 + */ xAxisType: { type: String, default: 'category', @@ -50,47 +94,75 @@ return ['category', 'value', 'time', 'log'].includes(value) }, }, - // 数据 + /** + * 数据,格式为[{name:'系列名',data:[0,0,0,...0], color:'可选'},...] + */ data: { type: Array, default: () => { return [] }, }, - // 单位 + /** + * 单位 + */ unit: { type: String, default: '', }, - // 颜色 + /** + * 颜色 + */ colors: { type: Array, - default: () => { return [] }, + default: () => { + return [ + '#2d8cf0', + '#19be6b', + '#ff9900', + '#E46CBB', + '#9A66E4', + '#ed3f14', + '#01C2F9', + ] + }, }, - // 实虚线 + /** + * 实虚线 + */ axisLineType: { type: String, default: '', }, - // 轴线颜色 + /** + * 轴线颜色 + */ axisLineColor: { type: String, default: '#96989b', }, - // 轴线上文字颜色 + /** + * 轴线上文字颜色 + */ fontColor: { type: String, default: '#000000', }, - // 是否为渐变折线图 + /** + * 是否为渐变折线图 + */ gradient: { type: Boolean, default: true, }, - // 标题 + /** + * 标题 + */ title: { type: String, default: '', }, - // 平滑 + /** + * 平滑 + */ smooth: { type: Boolean, default: true, @@ -114,25 +186,8 @@ // 构建option function buildOption() { const option: lineOption = { - grid: { - show: false, // 是否显示直角坐标系网格 - left: 10, - right: 20, - bottom: 5, - top: 50, - containLabel: true, // grid 区域是否包含坐标轴的刻度标签 - }, // 网格 - legend: { - show: props.legendShow, - icon: 'circle', - orient: 'vertile', // 图例方向 - align: 'left', // 图例标记和文本的对齐,默认自动 - top: 0, - itemWidth: 12, - itemHeight: 12, - padding: [0, 0, 0, 120], - right: 20, - }, // 图例 + grid: props.grid, + legend: props.legend, // 图例 tooltip: { trigger: 'axis', textStyle: { @@ -205,8 +260,8 @@ } } // 图例 - if (props.legend && props.legend.length > 0) { - option.legend!.data = props.legend + if (props.legend && props.legendData.length > 0) { + option.legend!.data = props.legendData } // x轴数据 if (props.xAxisData && props.xAxisData.length > 0) { diff --git a/src/components/Echart/PieChart.vue b/src/components/Echart/PieChart.vue index 797fd58..032ee81 100644 --- a/src/components/Echart/PieChart.vue +++ b/src/components/Echart/PieChart.vue @@ -9,21 +9,30 @@ import tdTheme from './theme.json' // 引入默认主题 import { formatColor, getAlphaColor } from './utils' const props = defineProps({ - // id + /** + * id + */ id: { type: String, default: 'chart', }, + /** + * 加载中 + */ loading: { type: Boolean, default: false, }, - // 标题 + /** + * 标题 + */ title: { type: String, default: '', }, - // 图例是否显示 + /** + * 图例是否显示 + */ legend: { type: Object, default: () => { @@ -41,47 +50,67 @@ } }, }, - // 文本标签是否显示 + /** + * 文本标签是否显示 + */ labelShow: { type: Boolean, default: true, }, - // 图表宽 + /** + * 图表宽 + */ width: { type: String, default: '100%', }, - // 图表高 + /** + * 图表高 + */ height: { type: String, default: '100%', }, - // 饼图的半径[内半径,外半径] + /** + * 饼图的半径[内半径,外半径] + */ radius: { type: Array, default: () => { return ['30%', '45%'] }, }, - // 是否要展示成玫瑰图,或玫瑰图类型:radius|area + /** + * 是否要展示成玫瑰图,或玫瑰图类型:radius|area + */ roseType: { type: [String, Boolean], default: false, }, - valueType: { // 显示值类型:percentage百分比|value数值 + /** + * 显示值类型:percentage百分比|value数值 + */ + valueType: { type: String, default: 'percentage', }, - // 数据 + /** + * 数据,格式为 [{name:'xxx',value:0},...] + */ data: { type: Array, default: () => { return [] }, }, - // 颜色 + /** + * 颜色 + */ colors: { type: Array, default: () => { return ['#3d7eff', '#caddff'] }, }, + /** + * 网格配置 + */ grid: { type: Object, default: () => { @@ -94,15 +123,30 @@ } }, }, - // 标签文字颜色 + /** + * 标签文字颜色 + */ fontColor: { type: String, default: '#000000', }, + /** + * 标签格式化 + */ labelFormatter: { type: String, default: '', }, + /** + * 标签位置, outside饼图扇区外侧, inside饼图扇区内部, center饼图中心位置 + */ + labelPosition: { + type: String, + default: 'center', + }, + /** + * 悬停格式化 + */ hoverFormatter: { type: String, default: '{b}
数量:{c}
占比:{d}%', @@ -127,14 +171,7 @@ // 构建option function buildOption() { const option: pieOption = { - grid: { - show: false, // 是否显示直角坐标系网格 - left: props.grid.left, - right: props.grid.right, - bottom: props.grid.bottom, - top: props.grid.top, - containLabel: props.grid.containLabel, // grid 区域是否包含坐标轴的刻度标签 - }, // 网格 + grid: props.grid, // 网格 legend: props.legend, // 图例 tooltip: { show: true, diff --git a/src/components/Echart/echart-interface.ts b/src/components/Echart/echart-interface.ts index 146e4fe..e677f65 100644 --- a/src/components/Echart/echart-interface.ts +++ b/src/components/Echart/echart-interface.ts @@ -9,7 +9,7 @@ // 饼图数据格式 export interface pieDataI { name: string // 分类名称 - value: number | string // 分类值 + value: number // 分类值 } // 标题配置 export interface titleOption {