MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / initChart

Function initChart

public/iframe/lib/js/mixinsComponents.js:44–240  ·  view source on GitHub ↗
(myChart, chartOption, option, id, name)

Source from the content-addressed store, hash-verified

42 });
43 },
44 async initChart(myChart, chartOption, option, id, name) {
45 // echarts组件公用初始化代码'
46 let xOry = 'xAxis'
47 option.data.forEach((item, index) => {
48 if (!option.series[index]) {
49 option.series.push(JSON.parse(JSON.stringify(option.series[0])))
50 }
51 })
52 chartOption = this.MergeRecursive(JSON.parse(JSON.stringify(option)), JSON.parse(JSON.stringify(chartOption))) // 合并基础配置和组件内自定义配置
53 option.data.forEach((item, index) => {
54 chartOption.series[index] = {...chartOption.series[index], ...item }
55 })
56 delete chartOption.data
57 if (option.legend) {
58 if (option.series[0].type === 'pie') {
59 option.data[0].data.forEach(item => {
60 chartOption.legend.data.push(item.name) // 当为饼图时循环data name作为legend的数据
61 })
62 } else {
63 chartOption.series.map(item => {
64 chartOption.legend.data.push(item.name) // name作为legend的数据
65 })
66 }
67
68 } else {
69 delete chartOption.legend
70 }
71 switch (name) {
72 case 'lineAndBar':
73 {
74 chartOption.xAxis.boundaryGap = true
75 chartOption.series[1].type = 'bar'
76 chartOption.series[1].barWidth = "25%"
77 };
78 break;
79 case 'mulityHorBar':
80 case 'stackHorBar':
81 {
82 delete chartOption.xAxis.data // 删除xAxis的data 属性 让图表横着摆
83 xOry = 'yAxis'
84 };
85 break;
86 case 'percentPie':
87 {
88 let sum = 0
89 option.data[0].data.map(item => {
90 sum += item.value
91 })
92 chartOption.title.text = `${option.data[0].data[0].value / sum * 100}%`
93 };
94 break;
95 case 'percent2Pie':
96 {
97 chartOption.series.push({
98 type: 'pie',
99 radius: ['40%', '70%'],
100 label: {
101 show: false,

Callers

nothing calls this directly

Calls 1

$Function · 0.70

Tested by

no test coverage detected