美文网首页
左右双柱状图

左右双柱状图

作者: 衬fzy | 来源:发表于2023-11-09 12:35 被阅读0次
微信截图_20231110123124.jpg

引入使用

import Number from './components/Left1'
<Left1 :id="`left1_1`" :datas="left1Obj"></Left1>

组件代码(感叹号最需要部分)

<template>
  <div :id="id" class="echarts1"></div>
</template>
<script>
import * as echarts from 'echarts'
export default {
  // startVal 初始值 endVal 最终值 title 标签值
  props: {
    datas: {
      type: [Array, Object],
      default: null
    },
    id: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      Time1: null,
      datasCopy: ''
    }
  },
  computed: {},
  watch: {
    // 这是监听json值变化
    datas: {
      // json为监听参数名
      handler: function (val, oldVal) {
        // 不能用箭头函数
        this.echartsFun(val)
      }
    }
  },
  beforeDestroy() {
    clearInterval(this.Time1)
  },
  methods: {
    echartsFun(val) {
      val = {
        data1: [11, 50, 7, 18, 35],
        data2: [17, 15, 27, 18, 35]
      }
      this.datasCopy = val
      // console.log(JSON.parse(JSON.stringify(this.datasCopy)))

      echarts.init(document.getElementById(this.id)).dispose() // 一定要摧毁
      const myChart = echarts.init(document.getElementById(this.id))
      myChart.clear()

      var option = {
        tooltip: {
          trigger: 'item',
          axisPointer: { // 坐标轴指示器,坐标轴触发有效
            type: 'line' // 默认为直线,可选为:'line' | 'shadow'
          },
          textStyle: {
            fontSize: 14
          }
        },
        "grid": [{
          "left": "11%",
          "right": "62%",
          "top": 30,
          "bottom": "10"
        }, {
          "left": "62%",
          "right": "11%",
          "top": 30,
          "bottom": "10"
        }, {
          "left": 0,
          "right": 0,
          "top": 0,
          "bottom": 0
        }],
        "xAxis": [
          {
            "type": "value",
            "gridIndex": 0,
            "inverse": true,
            // padding:[20,20,20,20],
            "axisLine": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "#ccc",
                "width": 1
              }
            },
            "axisTick": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#fff"
              }
            },
            "axisLabel": {
              "show": false,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 20,
              "color": "fff",
              "interval": "auto",
              "rotate": "0"
            },
            "data": []
          }, {
            "type": "value",
            "gridIndex": 1,
            "inverse": false,
            "axisLine": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "red",
                "width": 1
              }
            },
            "axisTick": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "axisLabel": {
              "show": false,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 12,
              "color": "#fff",
              "interval": "auto",
              "rotate": "0"
            },
            "data": []
          }, {
            "type": "value",
            "gridIndex": 2,
            "inverse": false,
            "axisLine": { // 只有这个
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "#ccc",
                "width": 1
              }
            },
            "axisTick": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "axisLabel": {
              "show": false,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 12,
              "color": "red",
              "interval": "auto",
              "rotate": "0"
            },
            "data": []
          }],
        "yAxis": [
          {
            "type": "category",
            "gridIndex": 0,
            "axisLine": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "red"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "#ccc",
                "width": 1
              }
            },
            "axisTick": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#888888"
              }
            },
            "axisLabel": {
              "show": true,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 12,
              "color": "#ffffff",
              "align": "center",
              "interval": "auto",
              "padding": [10, 0, 0, 310]// 左侧310,刚好居中
            },
            "data": ['境外平台', 'Telegram', 'Twitter', '境内数据'],
            "position": "left"
          }, {
            "type": "category",
            "gridIndex": 1,
            "axisLine": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#888888"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "#ccc",
                "width": 1
              }
            },
            "axisTick": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#888888"
              }
            },
            "axisLabel": {
              "show": false,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 16,
              "color": "#fff",
              "interval": "auto"
            },
            "data": []

          }, {
            "type": "category",
            "gridIndex": 2,
            "axisLine": {
              "show": false,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#888888"
              }
            },
            "splitLine": {
              "show": false,
              "lineStyle": {
                "type": "dotted",
                "color": "#ccc",
                "width": 1
              }
            },
            "axisTick": {
              "show": true,
              "lineStyle": {
                "width": 1,
                "type": "solid",
                "color": "#888888"
              }
            },
            "axisLabel": {
              "show": true,
              "fontFamily": "Microsoft YaHei",
              "fontSize": 16,
              "color": "#777575",
              "interval": "auto"
            }
          }],
        "series": [{
          "colId": "col402utokg",
          "name": '达赖',
          "type": "bar",
          //  type: 'pictorialBar',
          //  symbol: 'images', //可以使用自定义图片作为柱状图形
          //  symbol: 'image://' + BASE_PATH + '/pages/transportation/pages/supply/img/qianlvzz.png',
          "stack": null,
          "data": this.datasCopy.data1,
          barWidth: 10,
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                offset: 0,
                color: '#BCDCF6'
              }, {
                offset: 1,
                color: '#172F5B'
              }]),
              barBorderRadius: 12
            }
          },
          "xAxisIndex": 0,
          "yAxisIndex": 0,
          "label": {
            "position": "left",
            "fontFamily": "Microsoft YaHei",
            "show": true,
            "fontSize": 12,
            "color": "#fff",
            formatter: (series) => {
              return series.value + '条'
            }
          }
        }, {
          "colId": "col3kkgr6h9",
          "name": '班禅',
          "type": "bar",
          //  type: 'pictorialBar',
          //  symbol: 'images',  //可以使用自定义图片作为柱状图形
          //  symbol: 'image://' + BASE_PATH + '/pages/transportation/pages/supply/img/qianlanzz.png',
          "stack": null,
          "data": this.datasCopy.data2,
          barWidth: 10,
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                offset: 0,
                color: '#5B3117'
              }, {
                offset: 1,
                color: '#F6D1BC'
              }]),
              barBorderRadius: 12
            }
          },
          "xAxisIndex": 1,
          "yAxisIndex": 1,
          "label": {
            "position": "right",
            "fontFamily": "Microsoft YaHei",
            "show": true,
            "fontSize": 12,
            "color": "#fff",
            formatter: (series) => {
              return series.value + '条'
            }
          }
        }]
      };
      myChart.setOption(option, true) // true无数据时更新试图
    }
  }
}
</script>
<style lang="scss" scoped>
.echarts1 {
  width: 100%;
  height: 100%;
}
</style>

相关文章

  • R 数据可视化:双坐标系柱线图

    什么是双坐标系柱线图 啥么是双坐标系柱线图呢?就是为了在一张图中展示更丰富的信息,既有柱状图又有折线图。如果柱状图...

  • MySimpleChart(一个简单的图表库)--Android

    声明 MySimpleChart库是一个简单的图表库,里面包含单柱状图,双柱状图,条形图,扇形图等,此库在逐渐完善...

  • pyecharts柱状图进阶篇

    双纵坐标柱状图 如果想把温度和降雨量画在同一个柱状图内,一个纵坐标就不够用了 import pyecharts.o...

  • 小程序双柱状图

    注意要点: 1,通过小程序提供的canvas组件来绘制。需要注意地方是自定义的组件的包含canvas的时候,创建 ...

  • #Echarts# 双柱状图

    1、柱状图,正绿负红数据分组。 var score = [.......]; var scoreGreen = [...

  • 可视化库Highcharts-4-绘制柱状图2

    Highcharts-4-柱状图2 本文介绍了3种Highcharts中柱状图的制作: 堆叠柱状图 分组堆叠柱状图...

  • CSS布局与居中

    1.左右布局 双浮动|左右布局: 双浮动,左右布局,右边自适应 双浮动: 在子元素下面添加float,在父元素上面...

  • 用Tableau画帽子图(Hat Graphs)

    帽子图(Hat Graphs)是一个很有意思的图表,它是双柱状图的一种变形,主要是突出数值之间的差异。如下图,从双...

  • 可视化库Highcharts-3-绘制柱状图

    Highcharts绘制柱状图 本文介绍的是如何利用python-highcharts绘制柱状图 水平/垂直柱状图...

  • iOS图表制作-01

    基本的柱状图、折线图展示:(无交互事件) 一、柱状图展示 1、ZWChartContentView 柱状图承载视图...

网友评论

      本文标题:左右双柱状图

      本文链接:https://www.haomeiwen.com/subject/empcwdtx.html