• echarts 中如何添加左右滚动条 数据如何进行堆叠如何配置那些数据使用那个数据轴


    左右滚动条的效果

    此项的具体配置可参考 https://echarts.apache.org/zh/option.html#dataZoom-inside.moveOnMouseWheel

    dataZoom: [{
              id: 'dataZoomX',
              type: 'inside',
              // start: 0,
              // end: this.xAxis.length > 5 ? 10 : 100,
              startValue: this.xAxis.length > 5 ? 5 : 0,//数据窗口范围的起始数值(绝对数值)。如果设置了dataZoom-inside.start 则startValue失效。具体可以参考echarte中的配置项
              endValue: this.xAxis.length > 5 ? 9 : 100,
              zoomOnMouseWheel: false,//表示不按任何功能键,鼠标滚轮能触发缩放
              moveOnMouseMove: true,//表示不按任何功能键,鼠标移动能触发数据窗口平移
              moveOnMouseWheel: true//表示不按任何功能键,鼠标移动能触发数据窗口平移。
            }],
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    数据堆叠效果

    {
      name: '累计收入',
        type: 'bar',
        // 数据堆叠
        stack: 'total', 
        // 柱形图宽度
        barMaxWidth:8,
        // barGap:"50%",
        itemStyle:{
          color: '#FF7F50'
        },
        data:this.dataItem.accumulatedIncome
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    svg生成lengend图标

    legend: {
        top: 14,
        // right:3,
        itemHeight:10,
        itemWidth:12,
        textStyle:{
          fontSize:14,
          color:"#000"
        },
        data: [
          {name:"累计收入",icon:"path://m 0 -1 h 10 v 10 h -10z"},
          {name:"预计收入",icon:"path://m 0 -1 h 10 v 10 h -10z"},
          {name:"累计实际收入",icon:"path://m 0 -1 h 10 v 2 h -12z"},
          {name:"累计预计收入",icon:"path://m 0 -1 h 10 v 2 h -12z"}
        ]
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    demo代码

    <!-- eslint-disable eqeqeq -->
    <!-- eslint-disable no-undef -->
    <template>
      <div>
        <div ref='demo5' style="width:800px;height: 600px;"></div>
      </div>
    </template>
    <script>
    import * as echarts from "echarts";
    export default {
      data() {
        return {
          xAxis:['周一','周二','周三','周四','周五','周六','周日'],//横坐标
          dataItem:{
            accumulatedEstimate:[74, 19, 152, 101, 77, 99, 38],//累计预计收入
            accumulatedActual:[95, 110, 82, 181, 86, 98, 139],//累计实际收入
            expectedRevenue:[177, 68, 134, 202, 24, 184, 194],// 预计收入
            accumulatedIncome:[218, 39, 159, 49, 186, 80, 204],// 累计收入
          }
        }
      },
      async mounted() {
        this.initChart()
      },
      methods: {
        initChart() {
          let myChart = echarts.init(this.$refs.demo5);
          let option = {
            title:{
              show:false
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'shadow'
              },
              // 格式化弹窗中的内容
              formatter:(params)=>{
                let dateTime = params[0].axisValue
                // 生成
                let element = params.map(item => {
                  let width = '10px'
                  let height = '2px'
                  if (['累计收入','预计收入'].includes(item.seriesName)) {
                    width = '10px'
                    height = '10px'
                  }
                  return `
    ${width};height: ${height};background-color: ${item.color};margin-right: 8px;"> ${item.seriesName}
    ${item.value}
    `
    }).join(""); // 渲染 return `
    ${dateTime}
    ${element}
    `
    }, confine: true }, legend: { top: 14, // right:3, itemHeight:10, itemWidth:12, textStyle:{ fontSize:14, color:"#000" }, data: [ {name:"累计收入",icon:"path://m 0 -1 h 10 v 10 h -10z"}, {name:"预计收入",icon:"path://m 0 -1 h 10 v 10 h -10z"}, {name:"累计实际收入",icon:"path://m 0 -1 h 10 v 2 h -12z"}, {name:"累计预计收入",icon:"path://m 0 -1 h 10 v 2 h -12z"} ] }, grid: { left: '3%', right: '3%', bottom: '2%', containLabel: true }, // dataZoom: [{ // id: 'dataZoomX', // type: 'inside', // // start: 0, // // end: this.xAxis.length > 5 ? 10 : 100, // startValue: this.xAxis.length > 5 ? 5 : 0,//数据窗口范围的起始数值(绝对数值)。如果设置了dataZoom-inside.start 则startValue失效。 // endValue: this.xAxis.length > 5 ? 9 : 100, // zoomOnMouseWheel: false, // moveOnMouseMove: true, // moveOnMouseWheel: true // }], xAxis: [ { type: 'category', splitLine:{ show:false, }, axisTick:{ show:false, }, axisLine:{ show:false, }, axisPointer: { type: 'shadow' }, nameTextStyle:{ color: 'rgba(0,0,0,0.6)', fontWeight: 400, fontSize: 12 }, axisLabel:{ color: 'rgba(0,0,0,0.6)', fontWeight: 400, fontSize: 12 }, data:this.xAxis } ], yAxis: [ { name: "单位(万元)", type: 'value', min: 0, // max: 200000, // interval: 40000, axisPointer:{ show:false, }, // y轴名字的配置项 nameTextStyle:{ align:'left', padding: [0,0,0,-25], color: 'rgba(0,0,0,0.6)', fontWeight: 400, fontSize: 12 }, nameGap: 15, splitLine :{ lineStyle:{ type:'solid',//虚线 color: 'rgba(0,0,0,0.15)', width: 1, }, show: true //隐藏 } }, { type: 'value', name: "累计(万元)", min: 0, // max: 100, // interval: 20, axisLabel: { formatter: '{value}' }, splitLine:{ show:false, }, axisPointer:{ show:false, }, // y轴名字的配置项 nameTextStyle:{ align:'right', padding: [0,-25,0,0], color: 'rgba(0,0,0,0.6)', fontWeight: 400, fontSize: 12 }, nameGap: 15, } ], series: (()=>{ let series = [ { name: '累计收入', type: 'bar', // 数据堆叠 stack: 'total', // 柱形图宽度 barMaxWidth:20, // barGap:"50%", itemStyle:{ color: '#FF7F50' }, data:this.dataItem.accumulatedIncome }, { name: '预计收入', type: 'bar', // 数据堆叠 stack: 'total', // 柱形图宽度 barMaxWidth:20, // barGap:"50%", itemStyle:{ color: '#FFE4B5' }, data:this.dataItem.expectedRevenue }, { name: '累计实际收入', type: 'line', smooth: true, // 平滑曲线 // stack: 'total', // barMaxWidth:8, // barGap:"50%", itemStyle:{ color: '#800080', width: 2 }, // 使用双y轴的时候那些数据使用那个轴 yAxisIndex: 1, data:this.dataItem.accumulatedActual }, { name: '累计预计收入', type: 'line', smooth: true, // 平滑曲线 // stack: 'total', // barMaxWidth:8, // barGap:"50%", itemStyle:{ color:'#A0522D', width: 2 }, yAxisIndex: 1, data:this.dataItem.accumulatedEstimate }, ] return series })() } myChart.setOption(option, true); }, }, } </script> <style lang="scss" scoped> </style>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258

    效果如下

    在这里插入图片描述

  • 相关阅读:
    VS2022创建控制台应用程序后没有Main了,如何显示Main?
    springboot接收前端传参的几种方式
    掌握Python操作Word:从基础到高级全覆盖
    Electron内调用网页出现 $ is not defined 或者 jQuery is not defined
    c语言中使用openssl对rsa私钥解密
    Java自学路线图之Java进阶自学
    AI对室内设计师带来哪些新的机会以及影响 优漫动游
    rtmp htttp推流Windows桌面到srs进行播放
    Docker OCI runtime create failed
    # get请求和post请求的区别
  • 原文地址:https://blog.csdn.net/weixin_42343307/article/details/134487658