vue项目中使用dhtmlxGantt绘制甘特图

11 篇文章 0 订阅
1 篇文章 0 订阅

VUE+Element 基础上使用dhtmlxGantt绘制甘特图

安装依赖:

npm install dhtmlx-gantt

使用:

1、HTML

<template>
  <div class="gunter">
    <div ref="gantt" class="gunter-content" />
  </div>
</template>

2、javascript

<script>
import { gantt } from 'dhtmlx-gantt'
export default {
  data() {
    return {
      tasks: {
        data: [
          {
            id: 1,
            text: 'Task1',
            start_date: '2020-12-15',
            personName: '张总',
            duration: 3,
            progress: 0.6,
            color: '#1890FF'
          },
          {
            id: 2,
            text: 'Task2',
            start_date: '2020-12-18',
            personName: '李总',
            duration: 6,
            progress: 0.4,
            color: '#1890FF '
          },
          {
            id: 3,
            text: 'Task3',
            start_date: '2020-12-18',
            personName: '赵总',
            duration: 4,
            progress: 0.2,
            color: '#1890FF '
          },
          {
            id: 4,
            text: 'Task4',
            start_date: '2020-12-21',
            personName: '赵总',
            duration: 3,
            progress: 0,
            color: '#1890FF ',
            parent: 3
          }
        ],
        links: [{ id: 1, source: 1, target: 2, type: '0' }]
      }
    }
  },
  mounted: function () {
    this.initGunter()
  },
  methods: {
    /**
     * @description:初始化甘特图
     * @param {*}
     * @return {*}
     */
    initGunter() {
      // 甘特图只读
      //   gantt.config.readonly = true
      // 配置左侧树
      gantt.config.columns = [
        {
          name: 'text',
          label: '标题1',
          width: 217,
          tree: true,
          align: 'center',
          template: function (obj) {
            return `${obj.text}` // 通过 template 回调可以指定返回内容值
          }
        },
        {
          name: 'text',
          label: '标题2',
          width: 217,
          tree: true, // 如果有子元素是否遍历
          align: 'center',
          template: function (obj) {
            return `${obj.text}` // 通过 template 回调可以指定返回内容值
          }
        }
      ]
      // 配置右侧头部
      //   gantt.config.subscales = [
      //     {
      //       unit: 'day',
      //       step: 4,
      //       date: '%Y/%m/%d'
      //     }
      //   ]
      gantt.config.autoscroll = true
      //   gantt.config.autosize = 'xy'
      // 设置表头的高度
      gantt.config.scale_height = 66
      //   gantt.config.duration_unit = 'hour'
      //   gantt.config.duration_step = 6
      //   gantt.config.date_scale = '%H: %i'
      // 是否显示依赖连线
      gantt.config.show_links = true
      // 隐藏所有标记
      gantt.config.show_markers = true
      gantt.config.xml_date = '%Y-%m-%d'
      // 表头设置
      gantt.config.scales = [
        { unit: 'day', step: 1, format: '%Y/%m/%d' },
        { unit: 'hour', step: 6, format: '%H:%i' }
      ]
      gantt.init(this.$refs.gantt)
      gantt.parse(this.tasks)
    }
  }
}
</script>

3、css


<style lang="scss" scoped>
@import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
.gunter {
  height: 100%;
  margin-top: 11px;
  .gunter-content {
    height: 100%;
  }
}
</style>

效果图:

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值