F2支持微信小程序,开源库 https://github.com/antvis/wx-f2 https://github.com/antvis/f2-canvas



    1、首先下载wx-f2项目

    git clone https://github.com/antvis/wx-f2.git

    2、克隆下来之后,进行编译项目,需要node环境

    安装依赖

    npm i

    build dist文件

    npm run build

    查看package.json文件中的 build配置,最后执行cp脚本将f2依赖的代码拷贝到dist文件下的index.js文件中

    npm run cp

    3.在uniApp项目中创建wxcomponents文件夹

    详细查看:https://uniapp.dcloud.io/frame?id=小程序组件支持

    image.png

    4.配置page.json
    image.png
    5.使用如下图

    1. <template>
    2. <view class="chart-wrapper">
    3. <f2 :onInit="initChart"></f2>
    4. </view>
    5. </template>
    6. <script>
    7. let data = [
    8. { genre: 'Sports', sold: 275 },
    9. { genre: 'Strategy', sold: 115 },
    10. { genre: 'Action', sold: 120 },
    11. { genre: 'Shooter', sold: 350 },
    12. { genre: 'Other', sold: 150 }
    13. ];
    14. export default {
    15. data() {
    16. return {
    17. }
    18. },
    19. onLoad() {
    20. },
    21. methods: {
    22. initChart(F2,config) {
    23. const chart = new F2.Chart(config)
    24. chart.source(data)
    25. chart.interval()
    26. .position('genre*sold')
    27. .color('genre')
    28. chart.render()
    29. return chart
    30. }
    31. }
    32. }
    33. </script>
    34. <style>
    35. .chart-wrapper {
    36. width: 100%;
    37. height: 250px;
    38. }
    39. </style>