123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <template>
- <div ref="dom" style="width:100% ;height:300px;">
- </div>
- </template>
- <script>
- import * as echarts from "echarts";
- import {loadCategoryData} from '@/api/api';
- export default {
- name: "BarData",
- data() {
- return {
- a: [],
- b: [],
- sjyt: [],
- }
- },
- props: {
- resultXData: {},
- seriesName: {
- type: String,
- },
- titleText: {
- type: String,
- },
- dw: {
- type: String,
- },
- },
- mounted() {
- this.initDictConfig()
- /*setTimeout(() => {
- this.getPie();
- }, 1000)*/
- },
- created() {
- },
- watch: {
- resultXData: {
- handler(newVal) {
- this.$nextTick(function () {
- this.resultYData = newVal
- this.getPie()
- })
- },
- deep: true,
- immediate: true
- },
- },
- methods: {
- initDictConfig() {
- loadCategoryData({code: 'A04'}).then((res) => {
- if (res.success) {
- this.sjyt = res.result
- }
- })
- },
- getPie() {
- var _this = this;
- // 绘制图表
- /* this.$nextTick(() => {*/
- var option = {
- title: {
- text: this.titleText,
- x: 'left', //标题位置
- // textStyle: { //标题内容的样式
- // color: '#000',
- // fontStyle: 'normal',
- // fontWeight: 100,
- // fontSize: 16 //主题文字字体大小,默认为18px
- // },
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- }
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- data: this.resultYData.name,
- axisTick: {
- alignWithLabel: true
- },
- axisLabel: {
- interval: 0,
- rotate: 20,
- }
- }
- ],
- legend: {
- top: '5%', // 控制 板块控制器的位置
- right: 'center',
- // icon: 'rect',//形状 类型包括 circle,rect,line,roundRect,triangle,diamond,pin,arrow,none
- // itemWidth: 10, // 设置宽度
- // itemHeight: 4, // 设置高度
- itemGap: 40, // 设置两个legend之间的间距
- },
- yAxis: [
- {
- type: 'log',
- name: this.dw,
- splitLine: {
- lineStyle: {
- type: 'dashed',
- },
- },
- axisLabel: {
- // 轴文字
- fontSize: 12,
- },
- },
- ],
- series: [
- {
- name: this.seriesName,
- type: 'bar',
- barWidth: '50%',
- label: {
- show: true,
- position: 'top',
- },
- data: this.resultYData.value,
- itemStyle: {
- normal: {
- barBorderRadius: [10, 10, 0, 0],
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- {
- offset: 0,
- color: 'rgba(1,186,188,1)',
- },
- {
- offset: 1,
- color: 'rgba(150,214,104,.9)',
- },
- ]),
- }
- }
- },
- ]
- }
- // 使用刚指定的配置项和数据显示图表。
- var myChart = echarts.init(this.$refs.dom)
- myChart.on('click', (params) => {
- for (const param of this.sjyt) {
- if (param.title == params.name){
- _this.$emit('visible', {sjyt: param.value,sfsb:"3"});
- _this.$emit('visibleSz', {pzyt: param.value,sfsb:"3"});
- }
- }
- })
- myChart.setOption(option)
- }
- },
- }
- </script>
- <style scoped>
- </style>
|