diff --git a/src/components/Donut.jsx b/src/components/Donut.jsx
index ae3bccc..e7e5f2f 100644
--- a/src/components/Donut.jsx
+++ b/src/components/Donut.jsx
@@ -30,7 +30,7 @@ export default observer((props) => {
offset: '-50%',
autoRotate: false,
// content: '{value}',
- content: ({ percent }) => `${fixTo2Decimals(percent * 100)}%`,
+ content: ({ percent }) => percent > 0.02 ? `${fixTo2Decimals(percent * 100)}%`: '',
style: {
textAlign: 'center',
fontSize: 14,
diff --git a/src/components/LineWithKPI.jsx b/src/components/LineWithKPI.jsx
index f2d6c43..d06bee3 100644
--- a/src/components/LineWithKPI.jsx
+++ b/src/components/LineWithKPI.jsx
@@ -1,53 +1,36 @@
import { observer } from 'mobx-react';
import { Line } from '@ant-design/plots';
-import { merge, isEmpty, groupBy } from '../utils/commons';
+import { merge, isEmpty, groupBy, sortBy } from '../utils/commons';
import { dataFieldAlias } from '../libs/ht';
-const uniqueByKey = (array, key, pickLast) => {
- const seen = new Map();
- const isPickLast = pickLast === true;
-
- return array.filter(item => {
- const k = item[key];
- const storedItem = seen.get(k);
-
- if(storedItem) {
- if(isPickLast) {
- seen.set(k, item); // update with last item
- }
- return false;
- }
-
- seen.set(k, item);
- return true;
- });
-};
-
export default observer((props) => {
const { dataSource, ...config } = props;
const kpiKey = dataFieldAlias[config.yField]?.nestkey?.v;
const seriesData = groupBy(dataSource, ele => ele[config.seriesField]);
- const pickKey4KPI = Object.keys(seriesData)[0];
- const KPIData = (seriesData?.[pickKey4KPI] || []).reduce((r, v) => {
- if ( ! isEmpty(v[kpiKey])) { // 有设目标才多显示一条虚线 颜色: #F4664A
- r.push({...v, [config.yField]: v[kpiKey], [config.seriesField]: dataFieldAlias[kpiKey].label, extraLine: true,});
+ const splitData = dataSource.reduce((r, v) => {
+ r.push(v);
+ if ( ! isEmpty(v[kpiKey])) { // 有设目标才多显示一条虚线, 颜色和数据线一致
+ r.push({...v, [config.yField]: v[kpiKey], [config.seriesField]: `${v[config.seriesField]} ${dataFieldAlias[kpiKey].label}`, extraLine: true,});
}
return r;
- }, []);
- const dataColors = ['#598cf3', '#69deae', '#FAAD14'];
+ }, []).sort(sortBy(config.xField));
+ const dataColors = [
+ "#5B8FF9","#5AD8A6","#5D7092","#F6BD16","#6F5EF9","#6DC8EC","#945FB9","#FF9845","#1E9493",
+ "#FF99C3","#FF6B3B","#626681","#FFC100","#9FB40F","#76523B","#DAD5B5","#0E8E89","#E19348",
+ "#F383A2","#247FEA",
+ ];
const colorSets = Object.keys(seriesData).sort().reduce((obj, k, i) => ({...obj, [k]: dataColors[i]}), {});
const mergeLineConfig = merge({
- // color: ['#598cf3', '#69deae', '#F4664A', '#FAAD14'],
color: (item) => {
- const thisSeries = item[config.seriesField];
- return thisSeries.includes('目标') ? '#F4664A' : colorSets[thisSeries];
+ const thisSeries = item[config.seriesField].split(' ')?.[0];
+ return colorSets[thisSeries];
+ // return thisSeries.includes('目标') ? '#F4664A' : colorSets[thisSeries];
},
lineStyle: (data) => {
- // console.log(data);
if (data[config.seriesField].includes('目标')) {
return {
- lineDash: [4, 4],
- opacity: 0.5,
+ lineDash: [4, 8],
+ opacity: 0.7,
};
}
@@ -55,6 +38,10 @@ export default observer((props) => {
opacity: 1,
};
},
+ legend: {
+ custom: true,
+ items: Object.keys(seriesData).map((ele) => ({ id: ele, name: ele, value: ele, marker: { symbol: 'circle', style: { fill: colorSets[ele], color: colorSets[ele] } } })),
+ },
}, config);
- return