echarts使用笔记总结3:series使用方法

这是我学习vue-Echarts的笔记,并不是完全品。是我,对我使用Echarts时所用到的知识进行学习,有待后面补充完善。

上一节

一、饼图

(1)、饼图圆圈大小的调整series.radius

series.radius是一个[],数组的第一项是内半径(%),第二项是外半径(%)。
在这里插入图片描述

  series: [
            {
              name: '档案盒使用统计',
              type: 'pie',
              radius: ['60%', '85%'],//数组的第一项是内半径(%),第二项是外半径(%)。 
            }
          ]

(2)、完整代码配置

         option = {
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'
          },
          color: ['#4b77be', '#fe4848'],
          series: [
            {
              name: '档案盒使用统计',
              type: 'pie',
              radius: ['60%', '85%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: false
                }
              },
              labelLine: {
                show: false
              },
              data: [
                {
                  value: this.list.used,
                  name: '已使用'
                },
                {
                  value: this.list.notUsed,
                  name: '未使用'
                }
              ]
            }
          ]
        }

二、折线图

(1)、折线图的折线上标记的图形拐点常见的样式修改。

在这里插入图片描述

  • 图形拐点的形状series.symbol:
    circle(实心○), rect(□), roundRect(边框带弧度的□), triangle(△), diamond(◇), pin(水滴形),arrow (箭头形),none(无)
  • 图形拐点大小series.symbolSize = num,
  • 图形拐点的样式series.itemStyle.normal,
        series: [
            {
              name: '归还',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'circle', //拐点设置为实心圆
              itemStyle: {
                normal: {
                  color: '#3723f4',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              data: this.list.back_week
            },
            {
              name: '归档',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'arrow', //拐点设置为箭头形
              itemStyle: {
                normal: {
                  color: '#c523f4',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              data: this.list.file_week
            },
            {
              name: '借阅',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'none', //拐点不显示
              itemStyle: {
                normal: {
                  color: '#41f423',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              data: this.list.borrow_week
            },
            {
              name: '入库',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'pin', //拐点设置为水滴形
              itemStyle: {
                normal: {
                  color: '#f45e23',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              data: this.list.storage_week
            }
          ]

(2)、折线图的线样式修改series.lineStyle

        series: [
            {
              name: '归还',
              type: 'line',
              stack: 'Total',
              smooth: true,
              lineStyle: {
                width: 4,//线条粗细
                color: '#3723f4'//线条颜色
              },
              data: this.list.back_week
            },
            {
              name: '归档',
              type: 'line',
              stack: 'Total',
              smooth: true,
              lineStyle: {
                width: 4,//线条粗细
                color: '#c523f4'//线条颜色
              },
              data: this.list.file_week
            },
            {
              name: '借阅',
              type: 'line',
              stack: 'Total',
              smooth: true,
              lineStyle: {
                width: 4,//线条粗细
                color: '#41f423'//线条颜色
              },
              data: this.list.borrow_week
            },
            {
              name: '入库',
              type: 'line',
              stack: 'Total',
              smooth: true,
              lineStyle: {
                width: 4,//线条粗细
                color: '#f45e23'//线条颜色
              },
              data: this.list.storage_week
            }
          ]

(3)、完整代码配置

      option = {
          backgroundColor: '#021736', // echarts图表的背景颜色,默认为透明
          title: {
            text: '进7日案件流转分析',
            show: false
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            icon: 'rect',
            itemHeight: 6, //修改icon图形大小
            align: 'right', //修改图标和文字的前后位置
            textStyle: {
              color: '#c3cad9',
              fontSize: 18,
              fontFamily: 'SourceHanSansCN-Regular'
            },
            data: ['归还', '归档', '借阅', '入库']
          },
          color: ['#3723f4', '#c523f4', '#41f423', '#f45e23'],
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            boundaryGap: true, //为true时,不从圆点开始
            data: [
              '12/05',
              '12/06',
              '12/07',
              '12/08',
              '12/09',
              '12/10',
              '12/11'
            ],
            // x轴的字体样式
            axisLabel: {
              show: true,
              textStyle: {
                color: '#657ca8',
                fontSize: '14',
                fontFamily: 'SourceHanSansCN - Regular'
              }
            },
            // 控制网格线是否显示
            splitLine: {
              show: true,
              //  改变轴线颜色
              lineStyle: {
                // 使用深浅的间隔色
                color: '#192c4e'
              }
            },
            // x轴的颜色和宽度
            axisLine: {
              lineStyle: {
                color: '#192c4e',
                width: 1 //这里是坐标轴的宽度,可以去掉
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              show: true,
              textStyle: {
                color: '#657ca8',
                fontSize: '14',
                fontFamily: 'SourceHanSansCN - Regular'
              }
            },
            // y轴的颜色和宽度
            axisLine: {
              lineStyle: {
                color: '#192c4e',
                width: 1 //这里是坐标轴的宽度
              }
            },
            // 控制网格线是否显示
            splitLine: {
              show: true,
              //  改变轴线颜色
              lineStyle: {
                // 使用深浅的间隔色
                color: '#192c4e'
              }
            }
          },
          series: [
            {
              name: '归还',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'circle', //拐点设置为实心⚪
              itemStyle: {
                normal: {
                  color: '#3723f4',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              lineStyle: {
                width: 4, //线条粗细
                color: '#3723f4' //线条颜色
              },
              data: this.list.back_week
            },
            {
              name: '归档',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'arrow', //拐点设置为箭头形
              itemStyle: {
                normal: {
                  color: '#c523f4',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              lineStyle: {
                width: 4, //线条粗细
                color: '#c523f4' //线条颜色
              },
              data: this.list.file_week
            },
            {
              name: '借阅',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'none', //拐点设置为不显示
              itemStyle: {
                normal: {
                  color: '#41f423',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              lineStyle: {
                width: 4, //线条粗细
                color: '#41f423' //线条颜色
              },
              data: this.list.borrow_week
            },
            {
              name: '入库',
              type: 'line',
              stack: 'Total',
              smooth: true,
              symbolSize: 13, //改变折线上的圆点大小
              symbol: 'pin', //拐点设置为水滴形
              itemStyle: {
                normal: {
                  color: '#f45e23',
                  borderColor: '#fff', //拐点边框颜色
                  borderWidth: 1 //拐点边框大小
                }
              },
              lineStyle: {
                width: 4, //线条粗细
                color: '#f45e23' //线条颜色
              },
              data: this.list.storage_week
            }
          ]
        }

三、柱形图

(1)、给柱形图的柱子加上背景颜色series.backgroundStyle.color

在这里插入图片描述

       series: [
            {
              data: this.list.eight_year_data,
              type: 'bar',
              barWidth: 15,
              showBackground: true,
              backgroundStyle: {
                color: '#0b224d'//改变柱子的背景颜色
              },
            }
          ]

(2)、柱形图的柱子颜色渐变

在这里插入图片描述

        series: [{
                data: [18, 16, 8, 10, 5, 24],
                type: 'bar',
                showBackground: false,
                barWidth: '16px', //柱体宽度
                itemStyle: {
                    barBorderRadius: [2, 2, 0, 0], //柱体圆角   
                    color: new echarts.graphic.LinearGradient(
                        //前四个参数用于配置渐变色的起止位置,这四个参数依次对应 右下左上 四个方位。也就是从右边开始顺时针方向。
                        //通过修改前4个参数,可以实现不同的渐变方向
                        /*第五个参数则是一个数组,用于配置颜色的渐变过程。
                          每项为一个对象,包含offset和color两个参数
                        */
                        0, 0, 0, 1, [{//代表渐变色从正上方开始
                                offset: 0, //offset范围是0~1,用于表示位置,0是指0%处的颜色
                                color: '#09b0fa'
                            }, //柱图渐变色
                            {
                                offset: 1, //指100%处的颜色
                                color: '#2778ff'
                            }
                        ]
                    ),
                }
             ]

(3)、完整代码配置

        option = {
          tooltip: {
            trigger: 'axis'
          },
          title: {
            text: '总流转',
            top: '5%',
            textStyle: {
              fontSize: 17,
              color: '#ffffff',
              fontWeight: 'normal'
            }
          },
          xAxis: {
            type: 'category',
            boundaryGap: true, //为true时,不从圆点开始
            data: [
              '2019/6',
              '2019/7',
              '2019/8',
              '2019/9',
              '2019/10',
              '2019/11',
              '2019/12'
            ],
            // x轴的字体样式
            axisLabel: {
              interval: 0,
              show: true,
              textStyle: {
                color: '#657ca8',
                fontSize: '12',
                fontFamily: 'SourceHanSansCN - Regular'
              }
            },
            // 控制网格线是否显示
            splitLine: {
              show: true,
              //  改变轴线颜色
              lineStyle: {
                // 使用深浅的间隔色
                color: '#192c4e'
              }
            },
            // x轴的颜色和宽度
            axisLine: {
              lineStyle: {
                color: '#192c4e',
                width: 1 //这里是坐标轴的宽度,可以去掉
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              show: true,
              textStyle: {
                color: '#657ca8',
                fontSize: '12',
                fontFamily: 'SourceHanSansCN - Regular'
              }
            },
            // y轴的颜色和宽度
            axisLine: {
              lineStyle: {
                color: '#192c4e',
                width: 1 //这里是坐标轴的宽度
              }
            },
            // 控制网格线是否显示
            splitLine: {
              show: true,
              //  改变轴线颜色
              lineStyle: {
                // 使用深浅的间隔色
                color: '#192c4e'
              }
            }
          },
          series: [
            {
              data: this.list.eight_year_data,
              type: 'bar',
              barWidth: 15,
              showBackground: true,
              backgroundStyle: {
                color: '#0b224d'
              },
              itemStyle: {
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: '#09b0fa' // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: '#2778ff' // 100% 处的颜色
                    }
                  ],
                  global: false // 缺省为 false
                }
              }
            }
          ]
        }
  • 5
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
使用echarts绘制柱状图,你需要按照以下步骤进行操作: 1. 引入echarts的JavaScript文件。 2. 在HTML文件中创建一个div容器,用于显示图表[2]。 3. 通过初始化echarts对象,将图表与div容器进行绑定。 4. 设置图表的配置项,包括标题、x轴、y轴和数据系列等。可以根据需要设置不同的配置项,比如设置柱状图的颜色渐变效果。 5. 将配置项设置给echarts实例对象。 6. 最后,图表就会在div容器中显示出来。 以下是一个使用echarts绘制柱状图的示例代码: ```html <!DOCTYPE html> <html lang="en"> <head> <script src="js/echarts.min.js"></script> </head> <body> <div style="width: 600px;height: 400px"></div> <script> var mCharts = echarts.init(document.querySelector("div")); var option = { title: { text: '成绩', link: 'http://www.itcast.cn', textStyle: { color: 'red' } }, xAxis: { type: 'category', data: ['小明', '小红', '小王'] }, yAxis: { type: 'value' }, series: [ { name: '语文', type: 'bar', data: [70, 92, 87] } ] }; mCharts.setOption(option); </script> </body> </html> ``` 以上就是使用echarts绘制柱状图的基本步骤和代码示例。你可以根据自己的需求调整图表的配置项,来实现不同的样式和效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span> #### 引用[.reference_title] - *1* [echarts 柱状图渐变色背景](https://download.csdn.net/download/qq_36437172/12418565)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* *4* [ECharts的基本使用(一):柱状图与通用配置【第一日学习笔记】](https://blog.csdn.net/fzy2003/article/details/123689863)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值