初始化
This commit is contained in:
316
frontend/packages/G2Plots/饼图/基础饼图.js
Normal file
316
frontend/packages/G2Plots/饼图/基础饼图.js
Normal file
@@ -0,0 +1,316 @@
|
||||
|
||||
// 配置版本号
|
||||
const version = '2023111401'
|
||||
// 分类
|
||||
const category = 'Pie'
|
||||
// 标题
|
||||
const title = '基础饼图'
|
||||
// 类别, new Line()
|
||||
const chartType = 'Pie'
|
||||
// 用于标识,唯一,和文件夹名称一致
|
||||
const name = 'JiChuBinTu'
|
||||
|
||||
// 右侧配置项
|
||||
const setting = [
|
||||
{
|
||||
label: '维度',
|
||||
// 设置组件类型, select / input / colorPicker
|
||||
type: 'select',
|
||||
// 字段
|
||||
field: 'colorField',
|
||||
// 对应options中的字段
|
||||
optionField: 'colorField',
|
||||
// 是否多选
|
||||
multiple: false,
|
||||
value: '',
|
||||
// tab页。 data: 数据, custom: 自定义
|
||||
tabName: 'data'
|
||||
},
|
||||
{
|
||||
label: '指标',
|
||||
// 设置组件类型
|
||||
type: 'select',
|
||||
// 字段
|
||||
field: 'angleField',
|
||||
// 对应options中的字段
|
||||
optionField: 'angleField',
|
||||
// 是否多选
|
||||
multiple: false,
|
||||
value: '',
|
||||
tabName: 'data'
|
||||
},
|
||||
/** 样式配置 **/
|
||||
// 图表 graph
|
||||
{
|
||||
label: '标签文本来源',
|
||||
// 设置组件类型
|
||||
type: 'select',
|
||||
// 字段
|
||||
field: 'label_content',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.content',
|
||||
value: '{value}',
|
||||
tabName: 'custom',
|
||||
options: [
|
||||
{ label: '维度', value: '{name}' },
|
||||
{ label: '指标', value: '{value}' },
|
||||
{ label: '百分比', value: '{percentage}' }
|
||||
],
|
||||
step: 0.1,
|
||||
max: 1,
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签位置',
|
||||
// 设置组件类型
|
||||
type: 'select',
|
||||
// 字段
|
||||
field: 'label_type',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.type',
|
||||
value: 'inner',
|
||||
tabName: 'custom',
|
||||
options: [
|
||||
{ label: '外部', value: 'outer' },
|
||||
{ label: '内部', value: 'inner' },
|
||||
{ label: '蜘蛛布局', value: 'spider' }
|
||||
],
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '旋转内部标签',
|
||||
type: 'switch', // 设置组件类型
|
||||
field: 'labelAutoRotate', // 字段
|
||||
optionField: 'label.autoRotate', // 对应options中的字段
|
||||
value: true,
|
||||
active: true,
|
||||
inactive: false,
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签颜色',
|
||||
// 设置组件类型
|
||||
type: 'colorPicker',
|
||||
// 字段
|
||||
field: 'label_style_fill',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.style.fill',
|
||||
value: '#e9e9e9',
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签大小',
|
||||
// 设置组件类型
|
||||
type: 'inputNumber',
|
||||
// 字段
|
||||
field: 'label_style_fontSize',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.style.fontSize',
|
||||
value: 12,
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签线颜色',
|
||||
// 设置组件类型
|
||||
type: 'colorPicker',
|
||||
// 字段
|
||||
field: 'label_labelLine_style_stroke',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.labelLine.style.stroke',
|
||||
value: '#5B8FF9',
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签线宽度',
|
||||
type: 'inputNumber',
|
||||
field: 'label_labelLine_style_lineWidth',
|
||||
optionField: 'label.labelLine.style.lineWidth',
|
||||
value: 1,
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '标签线透明度',
|
||||
// 设置组件类型
|
||||
type: 'inputNumber',
|
||||
// 字段
|
||||
field: 'label_labelLine_style_opacity',
|
||||
// 对应options中的字段
|
||||
optionField: 'label.labelLine.style.opacity',
|
||||
value: '0.6',
|
||||
tabName: 'custom',
|
||||
step: 0.1,
|
||||
max: 1,
|
||||
groupName: 'graph'
|
||||
},
|
||||
{
|
||||
label: '饼图颜色',
|
||||
// 设置组件类型
|
||||
type: 'colorSelect',
|
||||
// 字段
|
||||
field: 'color',
|
||||
// 对应options中的字段
|
||||
optionField: 'color',
|
||||
value: ['#6b74e4', '#4391f4', '#38bbe5', '#69d6fd', '#36c6a0'],
|
||||
tabName: 'custom',
|
||||
groupName: 'graph'
|
||||
},
|
||||
// 图例 legend
|
||||
{
|
||||
label: '显示',
|
||||
type: 'switch', // 设置组件类型
|
||||
field: 'legendEnable', // 字段
|
||||
optionField: 'legendEnable', // 对应options中的字段
|
||||
value: true,
|
||||
active: true,
|
||||
inactive: false,
|
||||
tabName: 'custom',
|
||||
groupName: 'legend'
|
||||
},
|
||||
{
|
||||
label: '位置',
|
||||
type: 'select', // 设置组件类型
|
||||
field: 'legendPosition', // 字段
|
||||
optionField: 'legendPosition', // 对应options中的字段
|
||||
// 是否多选
|
||||
multiple: false,
|
||||
value: 'right',
|
||||
tabName: 'custom',
|
||||
options: [
|
||||
{ label: '顶部', value: 'top' },
|
||||
{ label: '左上角', value: 'top-left' },
|
||||
{ label: '右上角', value: 'top-right' },
|
||||
{ label: '左侧', value: 'left' },
|
||||
// { label: '左上方', value: 'left-top' },
|
||||
// { label: '左下方', value: 'left-bottom' },
|
||||
{ label: '右侧', value: 'right' },
|
||||
// { label: '右上方', value: 'right-top' },
|
||||
// { label: '右下方', value: 'right-bottom' },
|
||||
{ label: '底部', value: 'bottom' },
|
||||
{ label: '左下角', value: 'bottom-left' },
|
||||
{ label: '右下角', value: 'bottom-right' }
|
||||
],
|
||||
groupName: 'legend'
|
||||
},
|
||||
{
|
||||
label: '字体大小',
|
||||
type: 'inputNumber',
|
||||
field: 'legendItemName_style_fontSize',
|
||||
optionField: 'legendItemName.style.fontSize',
|
||||
value: 12,
|
||||
tabName: 'custom',
|
||||
groupName: 'legend'
|
||||
},
|
||||
{
|
||||
label: '字体权重',
|
||||
type: 'inputNumber',
|
||||
step: 100,
|
||||
max: 900,
|
||||
field: 'legendItemName_style_fontWeight',
|
||||
optionField: 'legendItemName.style.fontWeight',
|
||||
value: 400,
|
||||
tabName: 'custom',
|
||||
groupName: 'legend'
|
||||
},
|
||||
{
|
||||
label: '字体颜色',
|
||||
type: 'colorPicker',
|
||||
field: 'legendItemName_style_fill',
|
||||
optionField: 'legendItemName.style.fill',
|
||||
value: '#e9e9e9',
|
||||
tabName: 'custom',
|
||||
groupName: 'legend'
|
||||
},
|
||||
// 内边距 appendPadding
|
||||
{
|
||||
label: '',
|
||||
type: 'appendPadding',
|
||||
field: 'appendPadding',
|
||||
optionField: 'appendPadding',
|
||||
value: [0, 0, 0, 0],
|
||||
tabName: 'custom',
|
||||
groupName: 'appendPadding'
|
||||
}
|
||||
]
|
||||
|
||||
// 模拟数据
|
||||
const data = [
|
||||
{ type: '分类一', value: 27 },
|
||||
{ type: '分类二', value: 25 },
|
||||
{ type: '分类三', value: 18 },
|
||||
{ type: '分类四', value: 15 },
|
||||
{ type: '分类五', value: 10 },
|
||||
{ type: '其他', value: 5 }
|
||||
]
|
||||
|
||||
// 配置处理脚本
|
||||
const optionHandler = 'option.legend = option.legendEnable ? {position: setting.find(settingItem=>settingItem.field === \'legendPosition\').value} : false;' +
|
||||
'\n if (option.legendEnable) {\n' +
|
||||
' option.legend.itemName = option.legendItemName\n' +
|
||||
' }'
|
||||
|
||||
// 数据处理脚本
|
||||
const dataHandler = ''
|
||||
|
||||
// 图表配置 new Pie('domName', option)
|
||||
const option = {
|
||||
// 数据将要放入到哪个字段中
|
||||
dataKey: 'data',
|
||||
// 图表内边距
|
||||
appendPadding: [0, 0, 0, 0],
|
||||
renderer: 'canvas',
|
||||
data,
|
||||
legendEnable: true,
|
||||
legendLayout: 'vertical',
|
||||
legendPosition: 'right',
|
||||
angle: 0.5,
|
||||
angleField: 'value',
|
||||
colorField: 'type',
|
||||
radius: 0.9,
|
||||
legend: false,
|
||||
legendItemName: {
|
||||
style: {
|
||||
fill: '#e9e9e9',
|
||||
fontSize: 12,
|
||||
fontWeight: 400
|
||||
}
|
||||
},
|
||||
color: ['#6b74e4', '#4391f4', '#38bbe5', '#69d6fd', '#36c6a0'],
|
||||
pieStyle: {
|
||||
stroke: '#000000',
|
||||
lineWidth: 0
|
||||
},
|
||||
label: {
|
||||
autoRotate: true,
|
||||
type: 'inner',
|
||||
// offset: '-50%',
|
||||
labelLine: {
|
||||
style: {
|
||||
stroke: '#5B8FF9',
|
||||
opacity: 0.6,
|
||||
lineWidth: 1
|
||||
}
|
||||
},
|
||||
style: {
|
||||
fill: '#e9e9e9',
|
||||
fontSize: 14,
|
||||
textAlign: 'center'
|
||||
}
|
||||
},
|
||||
interactions: [{ type: 'element-active' }]
|
||||
}
|
||||
export default {
|
||||
category,
|
||||
version,
|
||||
title,
|
||||
chartType,
|
||||
name,
|
||||
option,
|
||||
setting,
|
||||
optionHandler,
|
||||
dataHandler
|
||||
}
|
||||
Reference in New Issue
Block a user