g2 plot示例

折线图示例

import React, { useEffect } from 'react';
import { Line } from '@antv/g2plot';


function LineCharts() {
    useEffect(() => {
        fetch('https://gw.alipayobjects.com/os/bmw-prod/55424a73-7cb8-4f79-b60d-3ab627ac5698.json')
            .then((res) => res.json())
            .then((data) => {
                const line = new Line('container', {
                    data,
                    xField: 'year',
                    yField: 'value',
                    seriesField: 'category',
                    xAxis: {
                        type: 'time',
                    },
                    yAxis: {
                        label: {
                            // 数值格式化为千分位
                            formatter: (v) => `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, (s) => `${s},`),
                        },
                        tickInterval:1900, //控制刻度间距
                    },
                });
    
                line.render();
            });
    }, [])
    return <div>
        <div className="container" id='container'></div>
    </div>
}

export default LineCharts;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
G2Plot-Vue 是一个基于 Vue.js 的数据可视化库,它是对 AntV G2Plot 的封装和扩展。G2Plot 是 AntV 团队开发的一套简单、易用且美观的图表库,可以用于在 Web 应用中创建各种类型的图表。而 G2Plot-Vue 则是为了更方便地在 Vue.js 项目中使用 G2Plot 而开发的。 通过 G2Plot-Vue,你可以使用 Vue.js 的语法和生命周期来创建和管理图表组件。它提供了一系列的组件,如折线图、柱状图、饼图等,可以快速创建交互丰富的图表,并支持自定义样式和配置。 要使用 G2Plot-Vue,你需要在 Vue 项目中安装相应的依赖并引入 G2Plot 相关的模块。你可以通过 npm 或 yarn 安装,并在代码中导入所需的组件。 例如,如果你想使用柱状图,你可以按照以下步骤进行操作: 1. 在项目中安装 G2Plot-Vue 的依赖: ``` npm install --save @antv/g2plot-vue ``` 2. 在需要使用柱状图的组件中导入 G2Plot-Vue: ```vue <template> <g2plot-bar :data="data" :x-field="xField" :y-field="yField"></g2plot-bar> </template> <script> import { G2PlotBar } from '@antv/g2plot-vue'; export default { components: { G2PlotBar, }, data() { return { data: [ { genre: 'Sports', sold: 275 }, { genre: 'Strategy', sold: 115 }, { genre: 'Action', sold: 120 }, { genre: 'Shooter', sold: 350 }, { genre: 'Other', sold: 150 }, ], xField: 'genre', yField: 'sold', }; }, }; </script> ``` 这样就可以在你的 Vue 组件中使用柱状图了。你可以根据需要修改数据、x 轴字段和 y 轴字段,并且可以根据 G2Plot 的文档自定义更多的图表样式和配置。 希望这个简单的示例能够帮助你开始使用 G2Plot-Vue 进行数据可视化。如果你有更多的问题,可以继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值