123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- <template>
- <div ref="chartRef" :style="{ height, width }"></div>
- </template>
- <script lang="ts" setup>
- import { ref, Ref, watch } from 'vue';
- import { useECharts } from '/@/hooks/web/useECharts';
- import { get } from 'lodash-es';
- import { ModuleDataChart } from '/@/views/vent/deviceManager/configurationTable/types';
- import { EChartsOption, graphic } from 'echarts';
- import { getData, getFormattedText } from '../../hooks/helper';
- import { getAssetURL } from '/@/utils/ui';
- const props = withDefaults(
- defineProps<{
- chartData: Record<string, any>[] | Record<string, any>;
- chartConfig: ModuleDataChart;
- height?: string;
- width?: string;
- }>(),
- {
- chartData: () => [],
- height: '100%',
- width: '100%',
- }
- );
- const chartRef = ref<HTMLDivElement | null>(null);
- const { setOptions, getInstance } = useECharts(chartRef as Ref<HTMLDivElement>);
- // 核心方法,生成适用与 echart 的选项,这个方法需要适配 chart 类型的每种子类型
- const genChartOption = () => {
- const inst = getInstance();
- const domWidth = inst ? inst.getWidth() : 500;
- // 依据每一个图表配置生成图表选项
- const { yAxis = [], xAxis = [], legend, order, type, sortBy, series, dataZoom = [] } = props.chartConfig;
- const textStyle = {
- color: '#fff',
- };
- let sorttedData: any[] = [];
- if (Array.isArray(props.chartData)) {
- sorttedData = props.chartData;
- } else {
- sorttedData = [props.chartData];
- }
- // 如果这个配置指明了需要排序则执行排序
- if (sortBy && order) {
- sorttedData.sort((pre, cur) => {
- if (order === 'asc') {
- return get(pre, sortBy, 0) - get(cur, sortBy, 0);
- } else {
- return get(cur, sortBy, 0) - get(pre, sortBy, 0);
- }
- });
- }
- // 该项作为下面所有图表依赖的基准系列数据
- const baseSeries: { name: string; data: [string, string][]; color: string }[] = sorttedData.reduce((res: any[], baseData) => {
- series.forEach((serie) => {
- // 将读取出的数据转为数组
- const temp = getData(baseData, serie.readFrom) || [];
- res.push({
- name: getFormattedText(baseData, serie.label),
- data: (Array.isArray(temp) ? temp : [temp]).map((data) => {
- return [getData(data, serie.xprop), getData(data, serie.yprop)]; /** x y */
- // return { name: getData(data, serie.xprop), value: getData(data, serie.yprop) }; /** x y */
- }),
- color: serie.color,
- });
- });
- return res;
- }, []);
- const baseDataZoom = dataZoom.map((e, i) => {
- return {
- type: 'slider',
- show: e.show,
- // show: get(baseSeries, '[0].data.length', 1) > e.maxAxisLength,
- xAxisIndex: i,
- end: e.end,
- };
- });
- // if (type === 'pie') {
- // return {
- // textStyle,
- // legend: {
- // textStyle,
- // show: legend.show,
- // },
- // tooltip: {
- // trigger: 'item',
- // },
- // color: ['#d9a1ff', '#00d1ff', '#82fe78'],
- // series: baseSeries.map((serie) => {
- // return {
- // type: 'pie',
- // radius: ['50%', '75%'],
- // center: ['50%', '55%'],
- // labelLine: { show: false },
- // label: { show: false },
- // itemStyle: {
- // shadowBlur: 20,
- // shadowColor: '#259bcf',
- // },
- // data: serie.data.map((e) => ({
- // name: e[0],
- // value: e[1],
- // })),
- // };
- // }),
- // };
- // }
- if (type === 'pie') {
- return {
- textStyle,
- legend: {
- textStyle,
- show: legend.show,
- },
- tooltip: {
- trigger: 'item',
- },
- color: ['#73C0DE', '#5470C6', '#91CC75', '#FAC858', '#ED6666', '#17d1b2', '#2ae271', '#11bce7', '#c127f0', '#ee125b'],
- series: baseSeries.reduce((curr: EChartsOption[], serie) => {
- const colors = ['#73C0DE', '#5470C6', '#91CC75', '#FAC858', '#ED6666', '#17d1b2', '#2ae271', '#11bce7', '#c127f0', '#ee125b'];
- if (baseSeries.length === 1) {
- curr.push({
- ...serie,
- type: 'pie',
- radius: ['30%', '64%'],
- center: ['50%', '55%'],
- z: 1,
- padAngle: 5,
- itemStyle: {
- shadowColor: 'rgba(0, 0, 0, 0.5)',
- borderWidth: 10,
- },
- label: {
- show: true,
- position: 'inner',
- formatter: '{d}%',
- color: '#fff',
- fontSize: 14,
- rich: {
- d: {
- fontFamily: '微软雅黑',
- fontSize: 16,
- color: '#fff',
- lineHeight: 30,
- },
- },
- },
- labelLine: { show: false },
- data: serie.data.map((e) => ({
- name: e[0],
- value: e[1],
- })),
- });
- curr.push({
- ...serie,
- type: 'pie',
- radius: ['64%', '74%'],
- center: ['50%', '55%'],
- labelLine: { show: false },
- label: { show: false },
- padAngle: 5,
- avoidLabelOverlap: false,
- itemStyle: {
- borderWidth: 10,
- normal: {
- color: function (obj) {
- return `${colors[obj['dataIndex']]}88`;
- },
- },
- },
- data: serie.data.map((e) => ({
- name: e[0],
- value: e[1],
- })),
- });
- }
- curr.push({
- ...serie,
- type: 'pie',
- radius: ['25%', '30%'],
- center: ['50%', '55%'],
- labelLine: { show: false },
- label: { show: false },
- z: 5,
- padAngle: 5,
- itemStyle: {
- borderWidth: 10,
- normal: {
- color: function (obj) {
- return `${colors[obj['dataIndex']]}88`;
- },
- },
- },
- data: serie.data.map((e) => ({
- name: e[0],
- value: e[1],
- })),
- });
- return curr;
- }, []),
- };
- }
- if (type === 'pie_halo') {
- // 光环的图片
- const img =
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADGCAYAAACJm/9dAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgo8P3hwYWNrZXQgZW5kPSJyIj8+IEmuOgAAE/9JREFUeJztnXmQVeWZxn/dIA2UgsriGmNNrEQNTqSio0IEFXeFkqi4kpngEhXjqMm4MIldkrE1bnGIMmPcUkOiIi6gJIragLKI0Songo5ZJlHGFTADaoRuhZ4/nnPmnO4+l+7bfc85d3l+VV18373n3Ptyvve53/5+da1L6jDdYjgwBhgNHALMBn6Sq0VdcxlwGvACsAx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lgr9VRGGAypU+SAijg7/DgF0LXLsZiWA2Cp68PgP7ypZarTEKMQzVIOPRr+rWJgivRkPA5cxVaIi1EJ+i2vAJVEOU7WrXtHCN0T3WovU+96DO6OEoksk4FNqn0n9F2tC+iGZUWy4CNuZqUZliYRRmI5pND2fUd0JDwKPRMGVLgfvKiRa0EegF1PxbDnyQq0UVwv8BNYmwIpIWBvwAAAAASUVORK5CYII=';
- const color = ['#70F081', '#EEE780', '#F07070', '#ffe000', '#ffa800', '#ff5b00', '#ff3000'];
- return {
- textStyle,
- legend: {
- textStyle,
- show: legend.show,
- },
- tooltip: {
- trigger: 'item',
- },
- graphic: {
- elements: [
- {
- type: 'image',
- z: 3,
- style: {
- image: img,
- width: 120,
- height: 120,
- },
- left: 'center',
- top: 'center',
- position: [20, 20],
- },
- ],
- },
- series: baseSeries.reduce((curr: EChartsOption[], serie) => {
- curr.push({
- ...serie,
- type: 'pie',
- clockWise: false,
- radius: [45, 45],
- label: {
- show: true,
- position: 'outside',
- color: '#ddd',
- formatter: get(legend, 'formatter', '{b}\n{c}pa'),
- },
- labelLine: {
- length: 30,
- length2: 40,
- show: true,
- color: '#00ffff',
- },
- data: serie.data.map((e, i) => ({
- name: e[0],
- value: e[1],
- itemStyle: {
- normal: {
- borderWidth: 10,
- shadowBlur: 30,
- borderColor: color[i],
- shadowColor: color[i],
- },
- },
- })),
- });
- return curr;
- }, []),
- };
- }
- if (type === 'pie_drag') {
- return {
- legend: baseSeries.map((e) => {
- return {
- orient: 'vertical',
- left: '54%',
- top: '8%',
- itemGap: 34,
- itemWidth: 10,
- itemHeight: 10,
- align: 'left',
- textStyle: {
- fontSize: 14,
- color: '#b3b8cc',
- },
- data: e.data.map((e) => {
- return `${e[0]}: ${e[1]}`;
- }),
- };
- }),
- graphic: {
- elements: [
- {
- type: 'image',
- style: {
- image: getAssetURL('home-container/pie.png'),
- width: 20,
- height: 100,
- },
- left: 'center',
- top: 'center',
- },
- ],
- },
- tooltip: {
- formatter: '{b}',
- },
- series: baseSeries.reduce((curr: EChartsOption[], serie) => {
- curr.push({
- radius: ['40%', '80%'],
- center: ['25%', '50%'],
- type: 'pie',
- z: 10,
- label: {
- show: false,
- },
- labelLine: {
- show: false,
- },
- itemStyle: {
- opacity: 0.7,
- },
- padAngle: 5,
- data: serie.data.map((e) => ({
- name: `${e[0]}: ${e[1]}`,
- value: e[1],
- })),
- });
- curr.push({
- radius: ['40%', '55%'],
- center: ['25%', '50%'],
- type: 'pie',
- z: 5,
- label: {
- show: false,
- },
- labelLine: {
- show: false,
- },
- animation: false,
- tooltip: {
- show: false,
- },
- padAngle: 6,
- data: serie.data.map((e) => ({
- name: `${e[0]}: ${e[1]}`,
- value: e[1],
- })),
- });
- return curr;
- }, []),
- };
- }
- // 柱状图
- if (type === 'bar') {
- return {
- textStyle,
- grid: {
- top: 50,
- bottom: dataZoom.length ? 70 : 50,
- },
- legend: {
- textStyle,
- show: legend.show,
- },
- tooltip: {
- trigger: 'item',
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- axisLabel: {
- interval: 0,
- width: baseDataZoom.length ? 100 : 800 / get(baseSeries, '[0].data.length', 1),
- overflow: 'break',
- },
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.reduce((curr: EChartsOption[], serie, index) => {
- const colors = ['#66ffff', '#ffff66'];
- if (baseSeries.length === 1) {
- curr.push({
- ...serie,
- type: 'pictorialBar',
- symbol: 'circle',
- symbolPosition: 'end',
- symbolSize: [20, 20],
- symbolOffset: [0, -10],
- barGap: '-100%',
- yAxisIndex: index,
- itemStyle: {
- color: colors[index % colors.length],
- },
- });
- }
- curr.push({
- ...serie,
- type: 'bar',
- silent: true,
- yAxisIndex: index,
- barWidth: 20,
- barGap: '100%',
- label: {
- show: true,
- textStyle,
- position: 'top',
- },
- itemStyle: {
- color: new graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: colors[index % colors.length] },
- { offset: 0.2, color: colors[index % colors.length] },
- { offset: 1, color: `${colors[index % colors.length]}22` },
- ]),
- borderRadius: [5, 5, 0, 0],
- },
- });
- return curr;
- }, []),
- };
- }
- // 折线图和上面的柱状图类似
- if (type === 'line') {
- return {
- textStyle,
- legend: {
- show: legend.show,
- top: 10,
- right: 10,
- textStyle,
- },
- grid: {
- left: 60,
- top: 40,
- right: 60,
- bottom: dataZoom.length ? 70 : 30,
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- axisLabel: {
- width: 100,
- overflow: 'break',
- },
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.map((serie) => {
- return {
- ...serie,
- type: 'line',
- };
- }),
- };
- }
- if (type === 'line_enhance') {
- return {
- textStyle,
- legend: {
- show: legend.show,
- top: 10,
- right: 10,
- textStyle,
- },
- tooltip: {
- trigger: 'item',
- },
- grid: {
- left: 60,
- top: 40,
- right: 60,
- bottom: dataZoom.length ? 70 : 30,
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- axisLabel: {
- width: 100,
- overflow: 'break',
- },
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- min: (value) => {
- return parseInt(value.min * 0.8);
- },
- max: (value) => {
- return parseInt(value.max * 1.2);
- },
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.map((serie) => {
- return {
- ...serie,
- type: 'line',
- };
- }),
- };
- }
- // 平滑曲线图
- if (type === 'line_smooth') {
- return {
- textStyle,
- legend: {
- show: legend.show,
- top: 10,
- textStyle,
- },
- grid: {
- left: 60,
- right: 60,
- bottom: dataZoom.length ? 70 : 30,
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.map((serie) => {
- return {
- ...serie,
- type: 'line',
- smooth: true,
- itemStyle: {
- opacity: 0,
- },
- };
- }),
- };
- }
- // 折线区域图,即折线下面的区域填满
- if (type === 'line_area') {
- return {
- textStyle,
- legend: {
- textStyle,
- show: legend.show,
- },
- grid: {
- left: 50,
- top: 50,
- right: 50,
- bottom: dataZoom.length ? 70 : 50,
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- boundaryGap: false,
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- color: '#fff',
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.map((serie, index) => {
- const colors = ['#66ffff', '#6666ff'];
- let color;
- if (serie.color) {
- color = serie.color;
- } else {
- color = colors[index % colors.length];
- }
- return {
- ...serie,
- type: 'line',
- symbol: 'none',
- endLabel: { distance: 0 },
- lineStyle: { color: color },
- areaStyle: {
- origin: 'auto',
- color: new graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: color },
- { offset: 0.2, color: color },
- { offset: 1, color: `${color}22` },
- ]),
- },
- };
- }),
- };
- }
- if (type === 'line_bar') {
- return {
- textStyle,
- legend: {
- textStyle,
- show: legend.show,
- top: 10,
- right: 10,
- },
- grid: {
- left: 40,
- top: 50,
- right: 40,
- bottom: dataZoom.length ? 70 : 10,
- show: false,
- },
- dataZoom: baseDataZoom,
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- };
- }),
- yAxis: yAxis.map((e) => {
- return {
- ...e,
- };
- }),
- series: baseSeries.map((serie, i) => {
- return {
- ...serie,
- type: i % 2 ? 'line' : 'bar',
- smooth: true,
- barWidth: 20,
- };
- }),
- };
- }
- // 堆叠柱状图
- if (type === 'bar_stack') {
- return {
- textStyle,
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow',
- },
- },
- grid: {
- top: 50,
- bottom: 30,
- },
- legend: {
- textStyle,
- show: legend.show,
- },
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- };
- }),
- yAxis: yAxis.map((e) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- color: 'rgba(21,80,126,0.3)',
- type: 'dashed',
- },
- },
- };
- }),
- series: baseSeries.map((serie) => {
- return {
- ...serie,
- type: 'bar',
- stack: 'stackME',
- barMaxWidth: '24',
- emphasis: {
- focus: 'series',
- },
- label: {
- show: true,
- position: 'top', //在上方显示
- textStyle: {
- //数值样式
- color: '#fff',
- fontSize: 14,
- },
- },
- };
- }),
- color: ['#F56731', '#00E8FF'],
- };
- }
- // 柱状图,圆柱形样式
- if (type === 'bar_cylinder') {
- return {
- textStyle,
- grid: {
- top: 40,
- bottom: 50,
- },
- legend: {
- textStyle,
- show: legend.show,
- },
- tooltip: {
- trigger: 'item',
- },
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- axisLabel: {
- interval: 0,
- width: (domWidth - 100) / get(baseSeries, '[0].data.length', 1),
- overflow: 'break',
- },
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.reduce((curr: EChartsOption[], serie, index) => {
- // const colors = ['#66ffff', '#00ff66', '#ffff66'];
- const colors = ['#73C0DE', '#ED6666', '#5470C6', '#91CC75', '#FAC858', '#17d1b2', '#2ae271', '#11bce7', '#c127f0', '#ee125b'];
- if (baseSeries.length === 1) {
- curr.push({
- ...serie,
- type: 'pictorialBar',
- symbol: 'circle',
- symbolPosition: 'end',
- symbolSize: [20, 10],
- symbolOffset: [0, -5],
- barGap: '-100%',
- yAxisIndex: index,
- itemStyle: {
- color: ({ dataIndex }) => colors[dataIndex % colors.length],
- },
- });
- curr.push({
- ...serie,
- type: 'pictorialBar',
- symbol: 'circle',
- symbolPosition: 'start',
- symbolSize: [20, 10],
- symbolOffset: [0, 5],
- barGap: '-100%',
- yAxisIndex: index,
- itemStyle: {
- color: ({ dataIndex }) => colors[dataIndex % colors.length],
- },
- });
- }
- curr.push({
- ...serie,
- type: 'bar',
- // silent: true,
- yAxisIndex: index,
- barWidth: 20,
- barGap: '100%',
- itemStyle: {
- color: ({ dataIndex }) =>
- new graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: `${colors[dataIndex % colors.length]}44` },
- { offset: 0.5, color: colors[dataIndex % colors.length] },
- { offset: 1, color: colors[dataIndex % colors.length] },
- ]),
- borderRadius: [5, 5, 0, 0],
- },
- label: {
- show: true, //开启显示
- position: 'top', //在上方显示
- textStyle: {
- //数值样式
- color: '#ffffffbb',
- fontSize: 13,
- },
- formatter: function (obj) {
- return obj['data'][1];
- },
- },
- });
- return curr;
- }, []),
- };
- }
- // 柱状图,圆柱形样式
- if (type === 'bar_cylinder_wide') {
- return {
- textStyle,
- grid: {
- top: 40,
- bottom: 50,
- },
- legend: {
- textStyle,
- show: legend.show,
- },
- tooltip: {
- trigger: 'item',
- },
- xAxis: xAxis.map((e) => {
- return {
- ...e,
- type: 'category',
- axisLabel: {
- interval: 0,
- width: (domWidth - 100) / get(baseSeries, '[0].data.length', 1),
- overflow: 'break',
- },
- };
- }),
- yAxis: yAxis.map((e, i) => {
- return {
- ...e,
- splitLine: {
- lineStyle: {
- opacity: i === 0 ? 0.1 : 0,
- },
- },
- };
- }),
- series: baseSeries.reduce((curr: EChartsOption[], serie, index) => {
- // const colors = ['#66ffff', '#00ff66', '#ffff66'];
- const colors = ['#73C0DE', '#ED6666', '#5470C6', '#91CC75', '#FAC858', '#17d1b2', '#2ae271', '#11bce7', '#c127f0', '#ee125b'];
- if (baseSeries.length === 1) {
- curr.push({
- ...serie,
- type: 'pictorialBar',
- symbol: 'circle',
- symbolPosition: 'end',
- symbolSize: [50, 10],
- symbolOffset: [0, -5],
- barGap: '-100%',
- yAxisIndex: index,
- itemStyle: {
- color: ({ dataIndex }) => colors[dataIndex % colors.length],
- },
- });
- curr.push({
- ...serie,
- type: 'pictorialBar',
- symbol: 'circle',
- symbolPosition: 'start',
- symbolSize: [50, 10],
- symbolOffset: [0, 5],
- barGap: '-100%',
- yAxisIndex: index,
- itemStyle: {
- color: ({ dataIndex }) => colors[dataIndex % colors.length],
- },
- });
- }
- curr.push({
- ...serie,
- type: 'bar',
- // silent: true,
- yAxisIndex: index,
- barWidth: 50,
- barGap: '100%',
- itemStyle: {
- color: ({ dataIndex }) =>
- new graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: `${colors[dataIndex % colors.length]}44` },
- { offset: 0.5, color: colors[dataIndex % colors.length] },
- { offset: 1, color: colors[dataIndex % colors.length] },
- ]),
- borderRadius: [5, 5, 0, 0],
- },
- label: {
- show: true, //开启显示
- position: 'top', //在上方显示
- textStyle: {
- //数值样式
- color: '#ffffffbb',
- fontSize: 13,
- },
- formatter: function (obj) {
- return obj['data'][1];
- },
- },
- });
- return curr;
- }, []),
- };
- }
- return {};
- };
- watch(
- () => props.chartData,
- () => {
- initCharts();
- },
- {
- immediate: true,
- }
- );
- function initCharts() {
- const o = genChartOption();
- setOptions(o as EChartsOption, false);
- }
- </script>
|