首页 > 其他分享 >折线图加柱状图

折线图加柱状图

时间:2024-05-31 09:31:56浏览次数:12  
标签:show color 柱状图 rgba offset 折线图 type 255

在data函数中定义数据myopiaList或从后端接口中拿到数据是个可以实时更新改变的echarts视图

 myopiaList:[24,50,70];

 initLineChart() {
      const myopiaData = Array.isArray(this.lineChartConfig.series)
        ? this.lineChartConfig.series
        : [];
      // 如果myopiaData是空数组,map方法会跳过执行,不会报错
      const nonMyopiaData = myopiaData.map((rate) => 100 - rate);
      const chartDom = document.getElementById("lineChart");
      const myChart = echarts.init(chartDom);

      const option = {
					title: {
				    text: '单位 / %',
				    textStyle: {
				      color: 'rgba(184, 211, 241, 1)',
				      fontSize: '12px',
				      textAlign: 'center',
				      fontWeight: "lighter"
				    }
				  },
				  color: {
				    x: 0,
				    y: 1,
				    x2: 0,
				    y2: 0,
				    colorStops: [
				      {
				        offset: 0,
				        color: 'rgba(21, 154, 255, 1)' // 0% 处的颜色
				      },
				      {
				        offset: 1,
				        color: 'rgba(0, 58, 255, 0)' // 100% 处的颜色
				      }
				    ],
				    global: false // 缺省为 false
				  },
				  xAxis: [
				    {
				      type: 'category',
				      data: ['小学', '初中', '高中'],
				      axisLine: {
				        lineStyle: {
				          color: '#0c3b71'
				        }
				      },
				      axisLabel: {
				        show: true,
				        color: 'rgb(170,170,170)',
								fontSize: 10,
								fontWeight: "lighter"
				      },
				      axisTick: {
				        show: false
				      }
				    },
				    {
				      type: 'category',
				      data: ['小学', '初中', '高中'],
						  show: false,
				    }
				  ],
				  yAxis: [
				    {
				      type: 'value',
				      max: 100,
				      splitLine: {
				        show: true, // 是否显示分隔线,默认数值轴显示
				        lineStyle: {
				          color: 'rgba(87, 206, 234, 1)', // 分隔线颜色
				          opacity: 0.1 // 分隔线透明度
				        }
				      },
				      axisLabel: {
				        textStyle: {
				          color: 'rgba(184, 211, 241, 1)', //更改坐标轴文字颜色
									fontSize: 10,
									fontWeight: "lighter"
				        }
				      },
				    },
				  ],
				  grid: {
				    x: 30,
				    y: 38,
				    x2: 10,
				    y2: 25,
				    borderWidth: 1
				  },
				  series: [
				    {
				      data: this.myopiaList,
				      type: 'bar',
				      barWidth: '10.5%',
							label: {
							  show: true,
							  position: 'top',
							  textStyle: {
									fontSize: 8,
							    color: 'rgba(184, 211, 241, 1)',
									fontWeight: "lighter"
							  }
							},
				      itemStyle: {
				        normal: {
				          color: {
				          type: 'linear',
									x: 0,
									x2: 0,
									y: 0,
									y2: 1,
				            colorStops: [
				              {
				                offset: 0,
				                color: "rgba(0, 199, 255, 1)", // 0% 处的颜色
				              },
				              {
				  							offset: 0.02,
				  							color: 'rgba(0, 199, 255, 1)'
				  						},
				              {
				                offset: 0.02,
				                color: "rgba(0, 58, 255, 0)", // 100% 处的颜色
				              },
				              {
				                offset: 1,
				                color: "rgba(21, 154, 255, 1)", // 100% 处的颜色
				              },				
				            ],
				          },
				        },
				      },
				    },
				    {
				      data: [100, 100, 100],
				      type: 'bar',
				      barWidth: '35%',
				      xAxisIndex: 1,
				      itemStyle: {
				        normal: {
				          color: 'rgba(108, 128, 151, 0.1)'
				        }
				      }
				    },
				    {
				      type: 'line',
				      symbol: `image://${dotImg}`,
				      symbolSize: 15,
				      lineStyle: {
				        color: 'rgba(255, 209, 92, 1)'
				      },
				      label: {
				        show: false,
				      },
				      data: this.myopiaList.map(index => Number(index) + 25),
				    }
				  ]
      };
      option && myChart.setOption(option);
    },

标签:show,color,柱状图,rgba,offset,折线图,type,255
From: https://blog.csdn.net/weixin_66412671/article/details/139310371

相关文章

  • amCharts绘制带趋势线折线图
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • amCharts绘制折线图尾部动画
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • amCharts绘制折线图和柱状图混合
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • amCharts绘制折线图比较
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • AnyChart绘制折线图
    代码案例<html><head><scriptsrc="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script><scriptsrc="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script......
  • 封装通用 ECharts 图表组件(四):分格柱状图实现
    在数据可视化的世界中,ECharts以其强大的功能和灵活性,成为了开发者们的首选图表库之一。继我们之前探讨的环形图封装之后,本文将带领大家进入另一个实用且美观的图表类型——分格柱状图的封装实现。分格柱状图简介分格柱状图是一种特殊的柱状图,它通过将每个柱子分割成多个小格......
  • 统计不同文件夹中的文件数量,并绘制相应的柱状图。
    一、数据类型每个文件夹下都是这种文件,虽然可以通过手动数出来了解文件数量,但为了更直观地看到每个文件夹的文件数量,可以使用图表来表示,这样会更加清晰。效果展示:  二、代码实现 importosimportmatplotlib.pyplotaspltfolder_names=['0','1','2','3']......
  • matplotlib-折线图的常用操作合集
    序言:感悟:复杂的折线图,都是由基础的折线图慢慢加工绘制而成,我们通过绘制出基本折线图,然后分析需要添加的功能,慢慢润色图形即可完成复杂的图形绘制。折线图:以折线的上升或下降来表示统计数量的增减变化的统计图特点:能够显示数据的变化趋势,反映事物的变化情况。(变化)我们以一个......
  • ZingChart折线图
    代码案例,参考<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>ZingSoftDemo</title><scriptnonce="undefined"src="https://cdn.zingchart.com/zingchart.min.js"></scrip......
  • echarts-柱状图翻转 适合排名展示 越小越大,越大越小
    先上效果(折线图也可,看代码中标注*的位置):代码:dataList=[1,2,9,8,10,14,3];//初始数值*dataList1=[];//翻转后的数值*vardd=2;//系数用来防止计算后为0不显示*maxValue=dataList[0];//*maxValue=Math.max(...dataList);//取最大值*[dataList1]......