| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- <template>
- <div class="chart-wrap">
- <div class="wrap-fix">
- <div class="col-1 col">
- <v-chart autoresize :option="option1"/>
- </div>
- <div class="col-2 col">
- <v-chart autoresize :option="option2"/>
- </div>
- </div>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts'
- import {chartMapTable} from '@/api/dashboard-json'
- export default {
- name: 'Jryl',
- data() {
- return {
- option1: {},
- option2: {}
- }
- },
- created() {
- this.getOption()
- },
- methods: {
- async getOption() {
- let arrMap = []
- const res = await chartMapTable()
- if (res.code === 200) {
- arrMap = [
- [res.info.series[0].data[0], res.info.series[1].data[0]],
- [res.info.series[0].data[1], res.info.series[1].data[1]],
- [res.info.series[0].data[2], res.info.series[1].data[2]]
- ]
- }
- var xData2 = ['变电']
- var data = arrMap || [
- [50, 10],
- [100, 10],
- [80, 10]
- ]
- const data1 = [
- [data[0][0]],
- [data[1][0]],
- [data[2][0]]
- ]
- const data2 = [
- [data[0][1]],
- [data[1][1]],
- [data[2][1]]
- ]
- const xDataSum = [arrMap[0][0] + arrMap[1][0] + arrMap[2][0], arrMap[0][1] + arrMap[1][1] + arrMap[2][1]]
- window['xDataSum'] = xDataSum
- const gapWidth = this.EchartfontSize(125)
- const barWidth = this.EchartfontSize(10)
- const symbolOffsetWidth = this.EchartfontSize(1)
- const symbolSizeWidth = this.EchartfontSize(4)
- const barGap = 10
- const params = {
- xData2: xData2,
- data: data2,
- gapWidth,
- barWidth,
- symbolOffsetWidth,
- symbolSizeWidth,
- barGap,
- xDataSum
- }
- this.renderOption('option1', params)
- const params2 = {
- xData2: ['电力'],
- data: data1,
- gapWidth,
- barWidth,
- symbolOffsetWidth,
- symbolSizeWidth,
- barGap,
- xDataSum
- }
- this.renderOption('option2', params2)
- },
- renderOption(optionName, params) {
- const {
- xData2,
- data,
- gapWidth,
- barWidth,
- symbolOffsetWidth,
- symbolSizeWidth,
- barGap,
- xDataSum
- } = params
- window['params'] = params
- window['tis'] = this
- let sealingData = []
- const gapPerSize = 3
- const gapData = data.map((item) => {
- if (item[0] === 0) {
- return [0, 0, 0]
- } else {
- return [gapPerSize, gapPerSize, gapPerSize]
- }
- })
- data.forEach((item, index) => {
- let sealingBeforeItem = item
- let sealingStart = [0, 0, 0]
- let sealingEnd = sealingBeforeItem
- if (index > 0) {
- sealingBeforeItem = sealingData[index - 1][1]
- sealingStart = sealingBeforeItem.map((d) => {
- if (d > 0) {
- return d + gapPerSize
- } else {
- return d
- }
- })
- sealingEnd = sealingBeforeItem.map((d, dIndex) => {
- if (d > 0) {
- return d + gapPerSize + item[dIndex]
- } else {
- return d + item[dIndex]
- }
- })
- }
- sealingData[index] = [sealingStart, sealingEnd]
- })
- // 三条数据变两条
- sealingData = JSON.parse(JSON.stringify(sealingData))
- sealingData.forEach((item, index) => {
- const start = item[0].splice(0, data[0].length)
- const end = item[1].splice(0, data[0].length)
- sealingData[index] = [start, end]
- })
- this[optionName] = {
- tooltip: {
- show: false,
- trigger: 'item'
- },
- legend: {
- selectedMode: false,
- show: optionName !== 'option2',
- top: '5%',
- right: '30%',
- width: '100%',
- height: '0%',
- // orient: 'vertical',
- textStyle: {
- color: '#ffffff',
- fontSize: this.EchartfontSize(12)
- },
- data: [
- {
- name: '一级',
- // 强制设置图形为圆。
- icon: `image://${window.location.origin}/static/images/icon_red@2x.png`,
- // 设置文本为红色
- textStyle: {
- color: '#ffffff'
- }
- },
- {
- name: '二级',
- // 强制设置图形为圆。
- icon: `image://${window.location.origin}/static/images/icon_yellow@2x.png`,
- // 设置文本为红色
- textStyle: {
- color: '#ffffff'
- }
- },
- {
- name: '三级',
- // 强制设置图形为圆。
- icon: `image://${window.location.origin}/static/images/icon_blue@2x.png`,
- // 设置文本为红色
- textStyle: {
- color: '#ffffff'
- }
- }
- ]
- },
- grid: {
- right: '10%',
- left: '5%',
- height: '80%',
- top: optionName === 'option2' ? '10%' : '50%',
- bottom: optionName === 'option2' ? '0%' : 0,
- containLabel: true
- },
- xAxis: {
- show: false,
- type: 'value',
- splitLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLine: {
- show: false
- },
- axisLabel: {
- show: true,
- fontSize: this.EchartfontSize(16),
- color: '#ffffff',
- formatter: (name) => {
- return name + ' '
- }
- }
- },
- yAxis: {
- data: xData2,
- type: 'category',
- splitLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLine: {
- show: false
- },
- axisLabel: {
- fontSize: this.EchartfontSize(12),
- color: 'rgba(255,255,255,0.8)',
- formatter: (name) => {
- return name + ' '
- }
- }
- },
- series: [
- { // 一级
- name: '一级',
- type: 'bar',
- stack: 'total',
- barGap: barGap, /* 多个并排柱子设置柱子之间的间距*/
- barCategoryGap: 10, /* 多个并排柱子设置柱子之间的间距*/
- barWidth: barWidth,
- itemStyle: { // lenged文本
- opacity: 1,
- color: () => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
- offset: 0,
- color: 'rgba(231, 73, 2, 0.30)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(231, 73, 2, 0.60)' // 100% 处的颜色
- }], false)
- }
- },
- label: {
- show: true,
- position: ['50%', -barWidth - 10],
- fontSize: this.EchartfontSize(16),
- color: '#ffffff',
- formatter: (evt) => {
- return data[0][0] > 0 ? (evt || {})?.value : ' '
- }
- },
- data: data[0]
- },
- { // gap
- name: '',
- type: 'bar',
- barWidth: gapWidth,
- stack: 'total',
- z: 0,
- itemStyle: {
- color: 'rgba(255,0,0,1)',
- opacity: 0
- },
- data: data[0][0] === 0 ? [0] : gapData[0]
- },
- { // 二级
- name: '二级',
- type: 'bar',
- stack: 'total',
- barWidth: barWidth,
- itemStyle: { // lenged文本
- opacity: 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(231, 203, 2, 0.30)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgb(72, 72, 36)' // 100% 处的颜色
- }], false)
- }
- },
- label: {
- show: true,
- position: ['50%', -barWidth - 10],
- fontSize: this.EchartfontSize(16),
- color: '#fffff',
- formatter: (evt) => {
- return data[1][0] > 0 ? evt.value : ' '
- }
- },
- data: data[1]
- },
- { // gap
- name: '',
- type: 'bar',
- barWidth: gapWidth,
- stack: 'total',
- z: 0,
- itemStyle: {
- color: 'rgba(255,0,0,1)',
- opacity: 0
- },
- data: data[1][0] === 0 ? [0] : gapData[1]
- },
- { // 三级
- name: '三级',
- type: 'bar',
- stack: 'total',
- barWidth: barWidth,
- itemStyle: { // lenged文本
- opacity: 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(78, 231, 255, 0.30)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(78, 231, 255, 0.60)' // 100% 处的颜色
- }], false)
- }
- },
- label: {
- show: true,
- position: ['50%', -barWidth - 10],
- fontSize: this.EchartfontSize(16),
- color: '#fffff',
- formatter: (evt) => {
- return data[2][0] > 0 ? evt.value : ' '
- }
- },
- data: data[2]
- },
- // { // 替代柱状图 默认不显示颜色,是最下方柱图(邮件营销)的value值 - 20
- // type: 'bar',
- // barWidth: barWidth,
- // barGap: '-100%',
- // stack: '广告',
- // itemStyle: {
- // color: 'transparent'
- // },
- // data: data1
- // },
- { // 封口1
- 'name': '',
- 'type': 'pictorialBar',
- 'symbol': 'circle',
- 'symbolRotate': 180,
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolOffset': [symbolOffsetWidth, 0],
- itemStyle: {
- opacity: data[0][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(237, 118, 101,.4)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(237, 118, 101, .0)' // 100% 处的颜色
- }], false)
- }
- },
- label: {},
- 'symbolPosition': 'start',
- 'data': [sealingData[0][0][0], sealingData[0][0][0]]
- },
- { // 封口2
- 'name': '',
- 'type': 'pictorialBar',
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolRotate': 180,
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'symbolPosition': 'end',
- 'z': 12,
- itemStyle: {
- opacity: data[0][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: 'rgba(237, 118, 101,1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(237, 118, 101, 1)' // 100% 处的颜色
- }], false)
- }
- },
- 'data': sealingData[0][1]
- },
- { // 封口3
- 'name': '',
- 'type': 'pictorialBar',
- 'symbol': 'circle',
- 'symbolRotate': 180,
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'z': 12,
- itemStyle: {
- opacity: data[1][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(255, 238, 91,.1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(255, 238, 91, .6)' // 100% 处的颜色
- }], false)
- }
- },
- label: {
- // show: true,
- // position: 'top',
- // fontSize: 16,
- // color: '#fff'
- // formatter:(item)=>{
- // console.log(item)
- // return 'ssss'
- // }
- },
- 'symbolPosition': 'end',
- 'data': sealingData[1][0]
- },
- { // 封口4
- 'name': '',
- 'type': 'pictorialBar',
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolRotate': 180,
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'symbolPosition': 'end',
- 'z': 12,
- itemStyle: {
- opacity: data[1][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 1,
- color: 'rgba(255, 238, 91, 1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(255, 238, 91, 1)' // 100% 处的颜色
- }], false)
- }
- },
- 'data': sealingData[1][1]
- },
- { // 封口5
- 'name': '',
- 'type': 'pictorialBar',
- 'symbol': 'circle',
- 'symbolRotate': 180,
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'z': 12,
- itemStyle: {
- opacity: data[2][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: data[2][0] === 0 ? 0 : 1,
- color: 'rgba(162, 237, 255,.1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(162, 237, 255,.6)' // 100% 处的颜色
- }], false)
- }
- },
- label: {
- // show: true,
- // position: 'top',
- // fontSize: 16,
- // color: '#fff'
- // formatter:(item)=>{
- // console.log(item)
- // return 'ssss'
- // }
- },
- 'symbolPosition': 'end',
- 'data': sealingData[2][0]
- },
- { // 封口6
- 'name': '',
- 'type': 'pictorialBar',
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolRotate': 180,
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'symbolPosition': 'end',
- 'z': 12,
- show: false,
- itemStyle: {
- opacity: data[2][0] === 0 ? 0 : 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(162, 237, 255,1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(162, 237, 255,1)' // 100% 处的颜色
- }], false)
- }
- },
- 'data': sealingData[2][1]
- },
- { // right-value
- 'name': '',
- 'type': 'pictorialBar',
- 'symbolSize': [symbolSizeWidth, barWidth],
- 'symbolRotate': 180,
- 'symbolOffset': [symbolOffsetWidth, 0],
- 'symbolPosition': 'end',
- 'z': 12,
- itemStyle: {
- opacity: 1,
- color: (params) => {
- return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
- offset: 0,
- color: 'rgba(162, 237, 255,0)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(162, 237, 255,0)' // 100% 处的颜色
- }], false)
- }
- },
- 'data': sealingData[2][1].map(value => value + 10),
- label: {
- show: true,
- distance: 10,
- color: '#fff',
- fontSize: this.EchartfontSize(14),
- // position: [-baseWidth - offsetWidth / this.EchartfontSize(10), -this.EchartfontSize(20)]
- position: 'right',
- formatter: (item) => {
- if (optionName === 'option1') {
- return xDataSum[1]
- } else {
- return xDataSum[0]
- }
- }
- }
- }
- ]
- }
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .chart-wrap {
- width: 100%;
- height: 100%;
- overflow: hidden;
- background: rgb(40, 42, 54, 0);
- .wrap-fix {
- height: 100%;
- width: 100%;
- display: flex;
- flex-direction: column;
- .col {
- flex: 1;
- flex-shrink: 0;
- }
- }
- }
- </style>
|