vue中使用echarts实现3d双色柱状图

效果图:

在这里插入图片描述

引入:

import * as echarts from 'echarts'

布局:

 <div id="bar3d" style="height: 260px;width:580px;margin: 0 auto;"></div>

具体实现代码:

 mounted() {
      this.initChart()
    },
 methods:{
	    initChart() {
        //绿色
        const data = [1700,800, 1700, 600,800,1700,800,1700,1700,800,1700,800];
        //蓝色
        const data2 = [2600,1400, 3350, 1400, 1400, 3350, 1400, 3350, 2600,1400,3350,1400];
        const sideData = data.map(item => item + 90);
        const sideData2 = data.map(item => item + 90);
	      var serveTBar = echarts.init(document.getElementById('bar3d'));
        serveTBar.setOption(getEcharts3DBar());
     
        function getEcharts3DBar () {
          //左侧 右侧 顶部
          //蓝色
			 var colorArr2 = ["rgba(11, 83, 128)", "rgba(2, 143, 224)", "rgba(11, 83, 128)"];
       //绿色
       var colorArr = ["rgb(12, 109, 122)", "rgba(1, 241, 228)", "rgb(12, 109, 122)"];
       //绿色
			 var color = {
				 type: "linear",
				 x: 0,
				 x2: 1,
				 y: 0,
				 y2: 0,
				 colorStops:  [
					 {
						 offset: 0,
						 color: colorArr[0],
					 },
					 {
						 offset: 0.5,
						 color: colorArr[0],
					 },
					 {
						 offset: 0.5,
						 color: colorArr[1],
					 },
					 {
						 offset: 1,
						 color: colorArr[1],
					 },
				 ],
			 };
       var color2 = {
				 type: "linear",
				 x: 0,
				 x2: 1,
				 y: 0,
				 y2: 0,
				 colorStops:  [
					 {
						 offset: 0,
						 color: colorArr2[0],
					 },
					 {
						 offset: 0.5,
						 color: colorArr2[0],
					 },
					 {
						 offset: 0.5,
						 color: colorArr2[1],
					 },
					 {
						 offset: 1,
						 color: colorArr2[1],
					 },
				 ],
			 };
       //柱子宽度
			 var barWidth = 15;
			 var option = {
				 tooltip: {
					 trigger: 'axis',
					 formatter: function (params) {
						 var str = params[0].name + ":";
						 params.filter(function (item) {
							 if (item.componentSubType == "bar") {
								 str += "<br/>" + item.seriesName + ":" + item.value;
							 }
						 });
						 return str;
					 },
				 },
         //图表大小位置限制
				 grid:{
					 x:'10%',
					 x2:'5%',
					 y:'15%',
					 y2:'15%',
				 },
				//  legend: {
				// 	 show:false,
				// 	 data:['绿色','蓝色'],
				// 	 textStyle:{
				// 		 color:'#fff',
				// 		 fontSize:'20'
				// 	 }
				//  },
				 xAxis: {
					 data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月','9月','10月','11月','12月'],
					 //坐标轴
					 axisLine :{
						 show:true,
						 lineStyle: {
							 width: 1,
							 color: '#214776'
						 },
						 textStyle:{
							 color:'#fff',
							 fontSize:'10'
						 }
					 },
					 type : 'category',
					 axisLabel :{
						 textStyle:{
							 color: '#C5DFFB',
							 fontWeight: 500,
							 fontSize:'14'
						 }
					 },
					 axisTick  :{
						 textStyle:{
							 color:'#fff',
							 fontSize:'16'
						 },
						 show: false,
					 },
           axisLine: {
                //坐标轴轴线相关设置。数学上的x轴
                show: true,
                lineStyle: {
                    type:'dashed',//线的类型 虚线
                    color: '#DEDEDE',
                },
            },
				 },
				 yAxis: {
          name: '厂屋租凭统计:',
            nameTextStyle: {
                color: '#DEDEDE',
                fontSize: 12,
                padding: 10,
            },
            min: 0,//最小
            max: 3500,//最大
            interval: 500,//相差
					 type : 'value',
           splitLine: {
                show: true,
               lineStyle: {
                     type:'dashed',//线的类型 虚线0
                     opacity:0.2//透明度
                },
            },
					 axisTick  :{
						 show:false
					 },
            axisLine: {
                show: false,
            },
					 //坐标值标注
					 axisLabel: {
						 show: true,
						 textStyle: {
							 color: '#C5DFFB',
						 }
					 },
				 },
				 series: [
          //中
					 {
						 z: 1,
						 name: '绿色',
						 type: "bar",
						 barWidth: barWidth,
						 barGap: "0%",
						 data: data,
						 itemStyle: {
               normal: {
                color: color,
                //柱形图上方标题
                label: {
                  show: true,
                  position: 'top',
                  textStyle: {
                    color: 'rgb(1, 255, 250)',
                    fontSize: 8
                  }
                },
              }
						 },
					 },
           //下
					 {
						 z: 2,
						 name: '绿色',
						 type: "pictorialBar",
						 data: sideData,
						 symbol: "diamond",
						 symbolOffset: ["-75%", "50%"],
						 symbolSize: [barWidth, 10],
						 itemStyle: {
							 normal: {
								 color: color
							 },
						 },
						 tooltip: {
							 show: false,
						 },
					 },
           //上
					 {
						 z: 3,
						 name: '绿色',
						 type: "pictorialBar",
						 symbolPosition: "end",
						 data: data,
						 symbol: "diamond",
						 symbolOffset: ["-75%", "-50%"],
						 symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
						 itemStyle: {
							 normal: {
								 borderWidth: 2,
								 color: colorArr[2]
							 },
						 },
						 tooltip: {
							 show: false,
						 },
					 },
					 {
						 z: 1,
						 name: '蓝色',
						 type: "bar",
						 barWidth: barWidth,
						 barGap: "50%",
						 data: data2,
						 itemStyle: {
              normal: {
                color: color2,
                //柱形图上方标题
                label: {
                  show: true,
                  position: 'top',
                  textStyle: {
                    color: 'rgb(2, 157, 246)',
                    fontSize: 8
                  }
                },
              }
						 },
					 },
					 {
						 z: 2,
						 name: '蓝色',
						 type: "pictorialBar",
						 data: sideData2,
						 symbol: "diamond",
						 symbolOffset: ["75%", "50%"],
						 symbolSize: [barWidth, 10],
						 itemStyle: {
							 normal: {
								 color: color2
							 },
						 },
						 tooltip: {
							 show: false,
						 },
					 },
					 {
						 z: 3,
						 name: '蓝色',
						 type: "pictorialBar",
						 symbolPosition: "end",
						 data: data2,
						 symbol: "diamond",
						 symbolOffset: ["75%", "-50%"],
						 symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
						 itemStyle: {
							 normal: {
								 borderWidth: 2,
								 color: colorArr2[2]
							 },
						 },
						 tooltip: {
							 show: false,
						 },
					 },
				 ],
			 };
			 return option;
		 }
	    },
    },

有人知道如何改成从上到下的那种渐变么 ε=(´ο`*)))唉

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Echarts实现立体柱状图,可以使用Echarts3D效果。以下是使用Vue框架和Echarts实现立体柱状图的步骤: 1. 安装Echarts库:在Vue项目使用npm或yarn安装Echarts库。 ``` npm install echarts --save ``` 2. 在Vue组件引入Echarts库: ``` import echarts from 'echarts' ``` 3. 创建一个Echarts图表容器,例如: ``` <div ref="chart" style="width:600px;height:400px;"></div> ``` 4. 在Vue组件使用Echarts库的API创建一个立体柱状图: ``` mounted() { // 基于准备好的dom,初始化echarts实例 let myChart = echarts.init(this.$refs.chart); // 指定图表的配置项和数据 let option = { tooltip: {}, visualMap: { max: 20, inRange: { color: ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'] } }, xAxis3D: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis3D: { type: 'category', data: ['2012', '2013', '2014', '2015', '2016'] }, zAxis3D: { type: 'value' }, grid3D: { boxWidth: 200, boxDepth: 80, viewControl: { // projection: 'orthographic' }, light: { main: { intensity: 1.2, shadow: true }, ambient: { intensity: 0.3 } } }, series: [{ type: 'bar3D', data: [ [0, 0, 5], [0, 1, 1], [0, 2, 0], [0, 3, 2], [0, 4, 1], [1, 0, 1], [1, 1, 5], [1, 2, 3], [1, 3, 0], [1, 4, 2], [2, 0, 0], [2, 1, 3], [2, 2, 5], [2, 3, 1], [2, 4, 1], [3, 0, 2], [3, 1, 0], [3, 2, 3], [3, 3, 5], [3, 4, 2], [4, 0, 1], [4, 1, 2], [4, 2, 1], [4, 3, 2], [4, 4, 5] ], shading: 'lambert', label: { textStyle: { fontSize: 16, borderWidth: 1 } }, emphasis: { label: { textStyle: { fontSize: 20, color: '#900' } }, itemStyle: { color: '#900' } } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); } ``` 这是一个简单的立体柱状图示例,你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值