diff --git a/jeecgboot-vue3/src/components/chart/BarAndLine.vue b/jeecgboot-vue3/src/components/chart/BarAndLine.vue index 94feb23c..7943e26e 100644 --- a/jeecgboot-vue3/src/components/chart/BarAndLine.vue +++ b/jeecgboot-vue3/src/components/chart/BarAndLine.vue @@ -24,6 +24,10 @@ type: String as PropType, default: 'calc(100vh - 78px)', }, + customColor: { + type: Array, + default: () => [], + } }, setup(props) { const chartRef = ref(null); @@ -68,12 +72,15 @@ //轴数据 let xAxisData = Array.from(new Set(props.chartData.map((item) => item.name))); let seriesData = []; - typeArr.forEach((type) => { + typeArr.forEach((type,index) => { let obj = { name: type }; let chartArr = props.chartData.filter((item) => type === item.type); //data数据 obj['data'] = chartArr.map((item) => item.value); obj['type'] = chartArr[0].seriesType; + if(props?.customColor && props?.customColor[index]){ + obj['color'] = props.customColor[index]; + } seriesData.push(obj); }); option.series = seriesData; diff --git a/jeecgboot-vue3/src/views/report/chartdemo/chartdemo.data.ts b/jeecgboot-vue3/src/views/report/chartdemo/chartdemo.data.ts index d87e0201..23d3db59 100644 --- a/jeecgboot-vue3/src/views/report/chartdemo/chartdemo.data.ts +++ b/jeecgboot-vue3/src/views/report/chartdemo/chartdemo.data.ts @@ -1,8 +1,10 @@ +const colors = ['#4db6ac', '#ffb74d', '#64b5f6', '#e57373', '#9575cd', '#a1887f', '#90a4ae', '#4dd0e1', '#81c784', '#ff8a65']; export const getData = (() => { let dottedBase = +new Date(); const barDataSource: any[] = []; const barMultiData: any[] = []; const barLineData: any[] = []; + const barLineColors: any[] = []; for (let i = 0; i < 20; i++) { let obj = { name: '', value: 0 }; @@ -44,6 +46,7 @@ export const getData = (() => { obj.value = Math.random() * 200; barLineData.push(obj); } + barLineColors.push(colors[j]); } - return { barDataSource, barMultiData, pieData, barLineData, radarData }; + return { barDataSource, barMultiData, pieData, barLineData, barLineColors,radarData }; })(); diff --git a/jeecgboot-vue3/src/views/report/chartdemo/index.vue b/jeecgboot-vue3/src/views/report/chartdemo/index.vue index 61e61770..df304ef9 100644 --- a/jeecgboot-vue3/src/views/report/chartdemo/index.vue +++ b/jeecgboot-vue3/src/views/report/chartdemo/index.vue @@ -38,7 +38,7 @@ - + @@ -71,7 +71,7 @@ import BarAndLine from '/@/components/chart/BarAndLine.vue'; const activeKey = ref('1'); - const { barDataSource, barMultiData, pieData, barLineData, radarData } = getData; + const { barDataSource, barMultiData, pieData, barLineData, radarData,barLineColors } = getData; const multiBarOption = { title: { text: '多列柱状图', left: 'center' }, };