本文介绍了需要将mxGraph与Angular 6集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个甘特图,并认为mxGraph甘特图可能是理想的解决方案.唯一的问题是将其集成到应用程序中.

I need to implement a gantt chart and think mxGraph Gantt could be the ideal solution. The only problem is with the integration of it in the application.

有人尝试过集成和实现它.如果是这样,请提供一些使用说明/说明.

Has anyone tried integrating and implementing it. If so , then please provide some directions/instructions on how to use it.

https://github.com/jgraph/mxgraph/

推荐答案

这是完整的解决方案:

有关不同的mxGraph存储库的一些详细信息:

Few details about different mxGraph Repos:

Repo-1: https://github.com/jgraph/mxgraph
        This is an official release repo of mxGraph. With npm issues.

Repo-2: https://bitbucket.org/jgraph/mxgraph2
        This is an official development repo of mxGraph. With npm issues.

If anyone wants to see what npm issues with these above repos(i.e. Repo-1 and Repo-2), then check these following issues:
            - https://github.com/jgraph/mxgraph/issues/169
            - https://github.com/jgraph/mxgraph/issues/175

Repo-3: https://bitbucket.org/lgleim/mxgraph2
        Fork of Repo-2. With npm fixes.

Repo-4: https://github.com/ViksYelapale/mxgraph2
        Fork of Repo-2. Merged npm fixes from Repo-3 as well. Added changes(i.e. required for local installation of mxGraph) to this repo.

步骤:

  1. 克隆Repo-4.另外,添加官方回购协议(即Repo-2)的远程版本,以获取最新的mxGraph更新/发行版/修复程序.

  1. Clone Repo-4. Also, add remote of the official repo(i.e. Repo-2) to take the latest mxGraph updates/release/fixes.

将目录更改为mxgraph2并运行npm install

Change directory to the mxgraph2 and run npm install

$ cd mxgraph2
$ npm install

$ cd mxgraph2
$ npm install

现在转到您的角度项目存储库并安装mxGraph(即我们在本地构建的mxgraph2).

Now go to your angular project repo and install mxGraph(i.e. mxgraph2 which we have build locally).

$ npm install /path/to/mxgraph2

例如npm install /home/user/workspace/mxgraph2

这将在package.json文件中添加如下所示的类似条目:

Which will add a similar entry as below in your package.json file:

"mxgraph": "file:../mxgraph2"

运行一次正常的npm安装.用于添加任何缺少/依赖的程序包.

Run normal npm install once. For adding any missing/dependency package.

$ npm install

现在我们将安装mxgraph类型

Now we will install mxgraph typings

注意-打字稿的最低要求为2.4.0

Note - Minimum required version of the typescript is 2.4.0

$ npm install lgleim/mxgraph-typings --save

现在您可以在应用程序中使用mxGraph.

Now you can use mxGraph in your app.

i. component.ts

i. component.ts

import { mxgraph } from "mxgraph";

declare var require: any;

const mx = require('mxgraph')({
  mxImageBasePath: 'assets/mxgraph/images',
  mxBasePath: 'assets/mxgraph'
});

.
.
.

ngOnInit() {
   // Note - All mxGraph methods accessible using mx.xyz
   // Eg. mx.mxGraph, mx.mxClient, mx.mxKeyHandler, mx.mxUtils and so on.

   // Create graph

   var container = document.getElementById('graphContainer');
   var graph = new mx.mxGraph(container);

   // You can try demo code given in official doc with above changes.
}

ii. component.html

ii. component.html

<div id="graphContainer"></div>

就是这样!

希望这会有所帮助.

这篇关于需要将mxGraph与Angular 6集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 11:29