antV之初始G6

1、什么是G6?

G6是关系数据可视化引擎,开发者可以基于G6扩展出属于自己的图分析应用或图编辑器应用。

2、安装方法

   (1)通过引入在线脚本资源

<!-- 引入在线资源 -->
<script src="https://gw.alipayobjects.com/os/antv/assets/g6/2.0.0/g6.js"></script>

    (2)通过引入本地脚本

<!-- 引入本地脚本 -->
<script src="./g6.js"></script>

     (3)通过npm 安装

     在项目中使用下列命令,安装G6 npm 包。

   
   npm install @antv/g6 --save

    然后使用import 或require进行引用

import G6 from '@antv/g6';

const graph = new G6.Graph({
  container: 'mountNode',
  width: 600,
  height: 300
});

3、简单的使用

(1)创建div 图表容器

   在页面的render或body部分创建一个div,并制定必须的属性id;

          <div className="chart_height" >
                    <div id="bmountNode" style={{width:'100%',height:'350px'}} ref="container" > </div>

           </div>

    (2)编写图绘制代码

           //绘制血缘关系图
    drawRangeMapCharts(data){

        let dagre = new G6.Plugins['layout.dagre']({
            rankdir: 'LR',//布局方向,根节点在左,往右布局
            nodesep: 50,    //节点距离
            ranksep: 50     //层次距离
        });
        let net = new G6.Net({
            id: 'bmountNode',
            height:300,
            fitView: 'autoZoom',
            plugins: [dagre]
        });
        net.node().shape('react'); //定义结点形状
        net.edge().shape('arrow');//定义箭头形状
        net.source(data.nodes, data.edges);//存入数据

        net.render();

}

    (3)获取数据----此处我采用静态数据

const data = {
    "nodes": [{
        "x":"200",
        "y":"200",
        "label":"occur_balance"+'\n'+"融资合约发生金额",
        "id": "node1"
    }, {
        "x":"200",
        "y":"200",
        "label":  "fin_close_balance"+'\n'+"收市融资负债金额",
        "id": "node2",
        "style":{
            fill:'#666666',
        }
    }, {
        "x":"300",
        "y":"100",
        "label":"total_close_debit"+'\n'+"当日两融金额",
        "id": "node3"
    }, {
        "x":"300",
        "y":"200",
        "label":"close_rate"+'\n'+"当日维保比例",
        "id": "node4"
    }, {
        "x":"300",
        "y":"300",
        "label": "total_close_asse"+'\n'+"当日总资产",
        "id": "node5"
    }],
    "edges": [{
        "source": "node1",
        "target": "node2",
        "id": "edge1"
    }, {
        "source": "node2",
        "target": "node3",
        "id": "edge2"
    }, {
        "source": "node2",
        "target": "node4",
        "id": "edge3"
    }, {
        "source": "node2",
        "target": "node5",
        "id": "edge4"
    }]

};

(4)效果图


完整代码:

import React from 'react';
import G6 from '@antv/g6';
import Plugins from '@antv/g6-plugins';
import {JfCard} from '../../common';
const data = {
    "nodes": [{
        "x":"200",
        "y":"200",
        "label":"occur_balance"+'\n'+"融资合约发生金额",
        "id": "node1"
    }, {
        "x":"200",
        "y":"200",
        "label":  "fin_close_balance"+'\n'+"收市融资负债金额",
        "id": "node2",
        "style":{
            fill:'#666666',
        }
    }, {
        "x":"300",
        "y":"100",
        "label":"total_close_debit"+'\n'+"当日两融金额",
        "id": "node3"
    }, {
        "x":"300",
        "y":"200",
        "label":"close_rate"+'\n'+"当日维保比例",
        "id": "node4"
    }, {
        "x":"300",
        "y":"300",
        "label": "total_close_asse"+'\n'+"当日总资产",
        "id": "node5"
    }],
    "edges": [{
        "source": "node1",
        "target": "node2",
        "id": "edge1"
    }, {
        "source": "node2",
        "target": "node3",
        "id": "edge2"
    }, {
        "source": "node2",
        "target": "node4",
        "id": "edge3"
    }, {
        "source": "node2",
        "target": "node5",
        "id": "edge4"
    }]
};

export default class BalanceTotalCount extends React.Component {

    constructor (props) {
        super(props);
        this.state = {
            title: this.props.title,//定义模块标题
            data:this.props.chartsdata,  //定义传入的数据
        };

    }
    componentDidMount(){
       this.setState(
       );
        this.drawRangeMapCharts(data);
    }

    //绘制图形
    refreshBloodRelateCharts(){
     drawRangeMapCharts(this.state.data);
    }

    //绘制血缘关系图
    drawRangeMapCharts(data){

        let dagre = new G6.Plugins['layout.dagre']({
            rankdir: 'LR',//布局方向,根节点在左,往右布局
            nodesep: 50,    //节点距离
            ranksep: 50     //层次距离
        });
        let net = new G6.Net({
            id: 'bmountNode',
            height:300,
            fitView: 'autoZoom',
            plugins: [dagre]
        });
        net.node().shape('react'); //定义结点形状
        net.edge().shape('arrow');//定义箭头形状
        net.source(data.nodes, data.edges);//存入数据
        net.render();
    }
    render(){
        //2、创建dom
        return(
            <JfCard title={this.state.title} bordered={false} loading={this.state.loading} hasTip={this.props.hasTip}>
                <div className="chart_height" >
                    <div id="bmountNode" style={{width:'100%',height:'350px'}} ref="container" > </div>
                </div>
            </JfCard>
        );
    }
}


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值