【ECharts】柱状图

柱状图-Tootip嵌套折线图

在这里插入图片描述

let barChart = echarts.init(document.getElementById('bar_chart3'));
var xData = ['组A', '组B', '组C', '组D', '组E', '组F'];
var valueData = [9.5, 7.5, 8.6, 6.5, 5.5, 4.5];
var option = {
 title: {
   text: '柱状图-Tooltip显示折线图',
 },
 tooltip: {
   // 是否将tooltip限制在图表的区域内
   // confine: true,
   appendToBody: true,
   enterable: true,
   padding: 5,
   position: function(point, params, dom, rect, size) {
     var html = '<div style="width: 350px; height: 250px"></div>';
     dom.innerHTML = html;

     var myChart = echarts.init(dom.childNodes[0]);
     var myOption = {
       xAxis: {
         type: 'category',
         data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
       },
       yAxis: {
         type: 'value',
       },
       series: [
         {
           data: [150, 230, 224, 218, 135, 147, 260],
           type: 'line',
         },
       ],
     };
     myChart.setOption(myOption);

     return point;
   },
   formatter: ' ',
 },
 // 坐标轴指示器
 axisPointer: { show: true },
 xAxis: {
   type: 'category',
   data: xData,
   axisTick: {
     // 文字与刻度对齐
     alignWithLabel: true,
     color: '#C1C7D0',
   },
   axisLabel: {
     color: '#C1C7D0',
   },
 },
 yAxis: {
   type: 'value',
   name: '金额(万元)',
   nameTextStyle: {
     color: '#C1C7D0',
   },
   //网格线
   splitLine: {
     lineStyle: {
       type: 'dashed', //设置网格线类型 dotted:虚线 solid:实线
     },
   },
   axisTick: { show: false },
   axisLine: { show: false },
   axisLabel: { color: '#C1C7D0' },
 },
 series: [
   {
     type: 'bar',
     // silent: false,
     data: valueData,
     // 柱子宽度
     barWidth: 18,
     color: '#B9D5FF',
     // 柱体显示数值
     label: {
       show: true, //开启显示
       position: 'top', //在上方显示
       textStyle: {
         //数值样式
         color: 'black',
         fontSize: 12,
       },
     },
     // 高亮
     emphasis: {
       itemStyle: {
         color: '#1874FF',
       },
     },
   },
 ],
};
barChart.setOption(option);

barChart.on('mouseover', function(params) {
});
barChart.on('selectchanged', function(params) {
});
barChart.on('click', function(params) {
 // 取消之前高亮的图形
 // barChart.dispatchAction({
 //   type: 'downplay',
 //   seriesIndex: params.seriesIndex,
 //   dataIndex: params.dataIndex,
 // });
 // 高亮当前图形
 // barChart.dispatchAction({
 //   type: 'highlight',
 //   seriesIndex: params.seriesIndex,
 //   dataIndex: params.dataIndex,
 // });
});

柱状图 - 多个

在这里插入图片描述

let barChart4 = echarts.init(this.$refs.bar_chart4);
var xData = ['组A', '组B', '组C', '组D', '组E', '组F'];
var moneyData = [8.0, 23.2, 25.6, 76.7, 135.6, 162.2];
var numData = [10, 28, 70, 20, 18, 48];
var option = {
 tooltip: {
   trigger: 'axis',
   axisPointer: {
     type: 'cross',
     crossStyle: {
       color: '#999',
     },
   },
 },
 legend: {
   data: ['成交额', '成交量'],
   bottom: '0',
   itemWidth: 6,
   itemHeight: 6,
 },
 xAxis: [
   {
     type: 'category',
     data: xData,
     axisPointer: {
       type: 'shadow',
     },
   },
 ],
 yAxis: [
   {
     type: 'value',
     name: '金额:万元',
     min: 0,
     max: 250,
     interval: 50,
     axisLabel: {
       formatter: '{value} 万元',
     },
   },
   {
     type: 'value',
     name: '单位:数量',
     min: 0,
     max: 25,
     interval: 5,
     axisLabel: {
       formatter: '{value} ',
     },
   },
 ],
 series: [
   {
     name: '成交额',
     type: 'bar',
     barWidth: 20,
     data: moneyData,
     color: '#FBD444',
     tooltip: {
       valueFormatter: function(value) {
         return value + ' 万元';
       },
     },
     // 柱体上方显示数值
     label: {
       show: true,
       position: 'top',
     },
   },
   {
     name: '成交量',
     type: 'bar',
     barWidth: 20,
     data: numData,
     color: '#53C8D1',
     // 柱体上方显示数值
     label: {
       show: true,
       position: 'top',
     },
   },
 ],
};
barChart4.setOption(option);

柱状图 - X轴Y轴标记线

在这里插入图片描述

let barChart = echarts.init(document.getElementById('bar_chart5'));
var option = {
  title: {
    text: '柱状图-X轴Y轴连续值',
  },
  xAxis: {
    type: 'value',
    name: 'x轴',
  },
  yAxis: {
    type: 'value',
    name: 'y轴',
  },
  series: [
    {
      data: [
        [1, 120],
        [2, 200],
        [3, 150],
        [4, 80],
        [5, 70],
        [6, 110],
        [7, 130],
      ],
      type: 'bar',
      barMaxWidth: 18,
      markLine: {
        silent: true,
        symbol: ['none', 'none'],
        lineStyle: {
          width: 2,
          type: 'dotted',
          color: '#5B8FF9',
        },
        data: [
          {
            name: 'y轴标记线',
            yAxis: 120,
            label: {
              position: 'insideStartTop',
            },
          },
          {
            name: 'x轴标记线',
            xAxis: 4.5,
          },
        ],
      },
    },
  ],
};
barChart.setOption(option);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值