H5端vue2使用antv f2记录

附上3.x版本官网飞机票

  1. npm引入依赖包:npm install @antv/f2 --save 注意vue2我这里使用的3.8.11版本
  2. main.js中引用注册:
    import F2 from '@antv/f2';
    Vue.prototype.F2 = F2;
    
  3. 创建一个容器,给定宽高
    <div style="width: 100%; height: 300px">
    	<canvas id="LineChart" style="width: 100%; height: 100%"></canvas>
    </div>
    
  4. 定义数据集合
    list: [
    		{
    			mouth: "当月",
    			sales: 100,
    		},
    		{
    			mouth: "上月",
    			sales: 200,
    		},
    		{
    			mouth: "3月",
    			sales: 300,
    		},
    		{
    			mouth: "2月",
    			sales: 40,
    		},
    		{
    			mouth: "1月",
    			sales: 100,
    		},
    		{
    			mouth: "12月",
    			sales: 260,
    		},
    	]
    
  5. 初始化图表
    mounted() {
    	this.initChart();
    },
    methods: {
    	initChart() {
    		const chart = new this.F2.Chart({
    			id: "LineChart",
    			pixelRatio: window.devicePixelRatio,
    		});
    
    		chart.source(this.list);
    		chart.tooltip({
    			showCrosshairs: true,
    		});
    		chart.scale({
    			mouth: {
    				range: [0, 1],
    			},
    			sales: {
    				tickCount: 5,
    				min: 0,
    			},
    		});
    		chart.axis("mouth", {
    			label: function label(text, index, total) {
    				const textCfg = {};
    				if (index === 0) {
    					textCfg.textAlign = "left";
    				} else if (index === total - 1) {
    					textCfg.textAlign = "right";
    				}
    				return textCfg;
    			},
    		});
    		chart.area().position("mouth*sales");
    		chart.line().position("mouth*sales");
    		chart.render();
    	},
    }
    

h5中成品展示图
面积折线图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值