300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 【Vue ECharts开发】自定义echarts柱状图颜色渐变效果

【Vue ECharts开发】自定义echarts柱状图颜色渐变效果

时间:2021-07-10 10:15:59

相关推荐

【Vue ECharts开发】自定义echarts柱状图颜色渐变效果

1. 效果演示

2. 示例代码

Vue 模板代码:

<template><div><div id="main"></div></div></template><script>// JavaScript脚本代码...</script><style scoped>#main {width: 900px;height: 300px;}</style>

JavaScript脚本代码:

import * as echarts from 'echarts'export default {data() {return {chart: null,options: {}};},watch: {options: {deep: true,handler() {// 监听options值的变化,并重新渲染图表this.initChart()}}},mounted() {// 初始化ECharts对象this.chart = echarts.init(document.getElementById('main'))// 初始化图表配置项this.initOption()},methods: {initChart() {this.chart.setOption(this.options)},initOption() {this.options = {xAxis: {type: 'value',show: false // 不显示X轴},yAxis: [{// 定义左侧Y轴type: 'category',data: ['女装', '男装', '箱包', '饰品', '裤子'],offset: 10,axisLine: {show: false // 不显示坐标轴轴线},axisTick: {show: false // 不显示坐标轴刻度}},{// 定义右侧Y轴type: 'category',data: ['120', '100', '100', '90', '90'],position: 'right',nameTextStyle: {color: '#000'},axisLine: {show: false},axisTick: {show: false}}],grid: {// 绘制网格并设置偏移量show: true,top: '10%',left: '10%',right: '15%',bottom: '10%'},color: [{type: 'linear',x: 1,y: 1,x2: 0,y2: 0,colorStops: [ // 设置颜色渐变{offset: 0, color: 'rgba(63, 149, 206, 1)' },{offset: 1, color: 'rgba(30, 231, 231, 1)' }]}],series: [{type: 'bar',data: [120, 100, 100, 90, 90],showBackground: true, // 显示柱条的背景色barWidth: 20, // 设置柱条宽度}]}}},};

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。