f2 柱状图滚动 钉钉小程序_钉钉小程序图表库AntV - F2 使用总结

项目涉及图表部分的技术选型

对于图表这块的开发,使用一些流行的图表库可以大大提高我们的开发效率,目前较为流行的图表库大概有Echarts,Hcharts,AntV,他们都是大同小异,我印象比较深刻的是Hcharts是支持多坐标轴的,Echarts好像是不支持的,但是对于小程序的选择我们选择的是阿里的AntV-f2,因为他明确指出了适合小程序开发,而且AntV-f2除了不支持一些document,其他的大部分功能都是支持的,我们就没有再考虑其他的库,但是官方并没有太多关于小程序的具体使用文档,我们只能根据js的相关事例翻译成小程序的语法。

前期准备

AntV - F2的集成

安装f2

npm install @antv/f2 --save

安装my-f2 ,至于为什么要再包装一层my-f2,可以看下这篇文档 : 聊一聊 F2 与小程序

npm install @antv/my-f2

开发前需要了解一些图表的api,比如tooltip、guide、legend、coord 等。具体可参考api文档。

屏幕快照 2019-07-27 上午10.01.26.png

完成以上步骤后我们先来集成一个折线图吧

1.通过canvas创建一个图表

id="am-mc-line-{ {$id}}"

height="{ {height}}"

width="{ {width}}"

onTouchStart="t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要安装 Taro 和 Vue.js。然后,你可以使用 F2 来绘制基金净值走势图。 以下是一个基本的示例: 1. 在 Taro 项目中创建一个名为 Chart 的组件 ```jsx import Taro, { Component } from '@tarojs/taro' import { View } from '@tarojs/components' import F2 from '@antv/f2' import './chart.scss' class Chart extends Component { componentDidMount() { // 绘制图表 this.drawChart() } drawChart = () => { const chart = new F2.Chart({ el: this.refs.chart, width: Taro.pxTransform(750), height: Taro.pxTransform(300) }) const data = this.props.data // 传递基金净值数据 chart.source(data, { time: { type: 'timeCat', tickCount: 3, mask: 'MM-DD' } }) chart.axis('time', { 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.line().position('time*value') chart.render() } render() { return ( <View className='chart'> <canvas ref='chart'></canvas> </View> ) } } export default Chart ``` 2. 在 Taro 页面中使用 Chart 组件 ```jsx import Taro, { Component } from '@tarojs/taro' import { View } from '@tarojs/components' import Chart from '../../components/Chart' class Fund extends Component { config = { navigationBarTitleText: '基金净值走势' } state = { data: [ { time: '2019-01-01', value: 1.0 }, { time: '2019-02-01', value: 1.2 }, { time: '2019-03-01', value: 1.5 }, { time: '2019-04-01', value: 1.8 }, { time: '2019-05-01', value: 1.7 }, { time: '2019-06-01', value: 1.9 } ] } render() { return ( <View className='fund'> <Chart data={this.state.data} /> </View> ) } } export default Fund ``` 3. 将 Taro 项目构建为原生 APP 和小程序 你可以使用 Taro 提供的命令将 Taro 项目构建为原生 APP 和小程序。例如,要将 Taro 项目构建为微信小程序,你可以运行以下命令: ``` npm run build:weapp ``` 这将生成一个 dist/weapp 目录,其中包含用于微信小程序的代码。 对于原生 APP,你需要使用 Taro 提供的其他命令和工具来构建和打包应用程序。具体细节请参考 Taro 的文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值