vue中 使用antv g2 柱状图与折线图混合使用

爷爷没有输给战火,父亲没有输给贫穷,我却输给了和平年代的生活和爱情,以及太过自由

在这里插入图片描述

这是数据

data: [
 { time: '9:00-10:00', value: 30 , type: '曝光量', rate: 100 },
   { time: '10:00-11:00', value: 90, type: '曝光量', rate: 200 },
   { time: '11:00-12:00', value: 50, type: '点击量', rate: 300 },
   { time: '12:00-13:00', value: 30, type: '点击量', rate: 400 },
   { time: '13:00-14:00', value: 70, type: '点击量', rate: 500 }
 ],

这是组件


<template>
  <div class="page">
    <div :id="id"></div>
  </div>
</template>
<script type="text/ecmascript-6">
import { Chart } from '@antv/g2';

export default {
  name: 'Name', // Pascal命名
  components: {},
  props: {
    id: {
      type: String,
      default: 'chart'
    },
    height: {
      type: Number,
      default: 500
    },
    chartWidth: {
      type: Number,
    },
    chartData: {
      type: Array,
      default: () => {}
    },
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  filters: {},
  beforeCreate() {},
  created() {},
  mounted() {
    this.initPage();
  },
  methods: {
    initPage() {},
    drawChart() {
      const _this = this;
      const chart = new Chart({
        container: _this.id,
        autoFit: true,
        height: _this.height,
        width: _this.chartWidth
      });

      chart.data(_this.chartData);
      chart.scale({
        value: {
          alias: '销售额(万)',
          nice: true,
        },
        rate: {
          alias: '李大玄(百)',
          nice: true,
        },
      });
	chart.scale('reportDate', {
        tickInterval: 100,
      });
      chart.axis('rate', {
        title: {
          top: '0',
          style: {
            fill: 'green',
          },
        },
      });
      chart.axis('value', {
        title: {
          top: '0',
          style: {
            fill: 'green',
          },
        },
      });
      
      chart.tooltip({
        showCrosshairs: true, // 展示 Tooltip 辅助线
        showMarkers: false,
        shared: true,
      });
      chart.interaction('element-active');
      chart.legend({
        position: 'top',
        items: [
          { name: '曝光量', value: '曝光量', marker: { symbol: 'square', style: { fill: '#1890FF', r: 5 } } },
          { name: '点击量', value: '点击量', marker: { symbol: 'square', style: { fill: '#8c8c8c', r: 5 } } },
        ],
      });
      
      chart
        .interval()
        .adjust('stack')
        .color('type', ['red', 'pink'])
        .position('time*value')
        .style('time', val => {
          if (val === '13:00-14:00') {
            return {
              fillOpacity: 0.4,
              lineWidth: 1,
              stroke: '#636363',
              lineDash: [3, 2]
            };
          }
          return {
            fillOpacity: 1,
            lineWidth: 0,
            stroke: '#636363',
            lineDash: [100, 0.5]
          };
        });
      chart.line().position('time*rate').label('rate');
      chart.point().position('time*rate');
      // chart.interval().position('genre*sold');
      // chart.intervalDodge().position('date*value').color('type');
      chart.render();
    }
  },
};
</script>
<style lang="scss" scoped>

</style>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值