翻譯|使用教程|編輯:秦林|2022-09-23 09:57:22.800|閱讀 234 次
概述:本篇文章繼續(xù)給大家講解如何初始化dhtmlxGantt。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
將 dhtmlxGantt 文件導入基于 React 的應用程序的示例:
import React, { Component } from 'react'; import { gantt } from 'dhtmlx-gantt'; import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'; export default class Gantt extends Component { componentDidUpdate() { gantt.render(); } componentDidMount() { gantt.init(this.ganttContainer); gantt.parse(this.props.tasks); } render() { return ( <div ref={(input) => { this.ganttContainer = input }} style=width: '100%', height: '100%' ></div> ); } }
將 dhtmlxGantt文件導入基于 Angular 的應用程序的示例:
import {Component,ElementRef,OnInit,ViewChild,ViewEncapsulation} from '@angular/core'; import {TaskService} from '../services/task.service'; import {LinkService} from '../services/link.service'; import {Task} from '../models/task'; import {Link} from '../models/link'; import { gantt, Gantt } from 'dhtmlx-gantt'; @Component({ encapsulation: ViewEncapsulation.None, selector: 'gantt', styleUrls: ['./gantt.component.css'], providers: [TaskService, LinkService], template: `<div #gantt_here class='gantt-chart'></div>`, }) export class GanttComponent implements OnInit { @ViewChild('gantt_here') ganttContainer: ElementRef; constructor(private taskService:TaskService, private linkService:LinkService){ } ngOnInit() { gantt.config.xml_date = '%Y-%m-%d %H:%i'; gantt.init(this.ganttContainer.nativeElement); Promise.all([this.taskService.get(), this.linkService.get()]) .then(([data, links]) => { gantt.parse({ data, links }); }); } }
要將 dhtmlxGantt 文件包含到基于 RequireJS 的應用程序中,您需要遵循以下示例中顯示的邏輯:
requirejs(["codebase/dhtmlxgantt"], function(dhx){ var gantt = dhx.gantt; var Gantt = dhx.Gantt;// for Enterprise builds gantt.init("gantt_here"); gantt.parse({ data: [ { id:1, text:"Project #2", start_date:"01-04-2018", duration:18, progress:0.4, open:true }, { id:2, text:"Task #1", start_date:"02-04-2018", duration:8, progress:0.6, parent:1 }, { id:3, text:"Task #2", start_date:"11-04-2018", duration:8, progress:0.6, parent:1 } ], links: [ { id:1, source:1, target:2, type:"1" }, { id:2, source:2, target:3, type:"0" } ] }); });
dhtmlxGantt 庫將返回一個帶有字段的對象 gantt和 Gantt(在 Commercial、Enterprise 或 Ultimate 版本中)-甘特和甘特圖對象此處 。
下面的示例演示了如何以 custom_tooltip_plugin.js 正確的方式設置:
requirejs.config({ paths: { "dhtmlxgantt": "../../codebase/dhtmlxgantt", "ext/dhtmlxgantt_custom_tooltip": "../custom_tooltip_plugin" }, shim: { "ext/dhtmlxgantt_custom_tooltip": ["dhtmlxgantt"] } }); requirejs(["dhtmlxgantt"], function (dhx) { var gantt = dhx.gantt; var date_to_str = gantt.date.date_to_str(gantt.config.task_date); var today = new Date(2018, 3, 5); gantt.addMarker({ start_date: today, css: "today", text: "Today", title: "Today: " + date_to_str(today) }); gantt.init("gantt_here"); gantt.parse({ data: [ { id:1, text:"Project #2", start_date:"01-04-2018", duration:18, progress:0.4, open:true }, { id:2, text:"Task #1", start_date:"02-04-2018", duration:8, progress:0.6, parent:1 }, { id:3, text:"Task #2", start_date:"11-04-2018", duration:8, progress:0.6, parent:1 } ], links: [ { id:1, source:1, target:2, type:"1" }, { id:2, source:2, target:3, type:"0" } ] }); });
檢查包內任何文件的模塊名稱是否指定為包 的“代碼庫”文件夾內的相對路徑加上 文件名 ,例如:
核心庫:
要在不同的瀏覽器中以全屏模式正確顯示甘特圖,請在頁面上定義以下樣式:
<style type="text/css" media="screen"> html, body{ margin:0px; padding:0px; height:100%; overflow:hidden; } </style>
dhtmlxGantt是用于跨瀏覽器和跨平臺應用程序的功能齊全的Gantt圖表,可滿足項目管理控件應用程序的所有需求,是最完善的甘特圖圖表庫。了解更多DhtmlxGantt相關內容和資訊,歡迎在線咨詢或者私信我獲取正版試用版及報價。
甘特圖控件交流群:764148812 歡迎進群交流討論
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn