Highcharts甘特图开发带导航功能的项目管理图示例

Highcharts Gantt 的项目管理图通常把任务放在纵轴、时间放在横轴,并可用依赖关系表达任务先后。要加入时间导航,常用三种控件:

  • 时间范围按钮:快速切换一周、一个月或整个项目。
  • Navigator:在概览区域拖动选择要查看的时间段。
  • Scrollbar:沿时间轴平移查看其他日期。

下面是一个可运行示例,展示项目阶段、任务依赖、完成进度和导航控件。

javascript 复制代码
Highcharts.ganttChart('container', {

    title: {
        text: 'Gantt Chart with Navigation'
    },

    yAxis: {
        uniqueNames: true
    },

    navigator: {
        enabled: true,
        liveRedraw: true,
        series: {
            type: 'gantt',
            pointPlacement: 0.5,
            pointPadding: 0.25,
            accessibility: {
                enabled: false
            }
        },
        yAxis: {
            min: 0,
            max: 3,
            reversed: true,
            categories: []
        }
    },

    scrollbar: {
        enabled: true
    },

    rangeSelector: {
        enabled: true,
        selected: 0
    },

    accessibility: {
        point: {
            descriptionFormat: '{yCategory}. ' +
                '{#if completed}Task {(multiply completed.amount 100):.1f}% ' +
                'completed. {/if}' +
                'Start {x:%Y-%m-%d}, end {x2:%Y-%m-%d}.'
        },
        series: {
            descriptionFormat: '{name}'
        }
    },

    lang: {
        accessibility: {
            axis: {
                xAxisDescriptionPlural: 'The chart has a two-part X axis ' +
                    'showing time in both week numbers and days.',
                yAxisDescriptionPlural: 'The chart has one Y axis showing ' +
                    'task categories.'
            }
        }
    },

    series: [{
        name: 'Project 1',
        data: [{
            start: '2017-12-01',
            end: '2018-02-02',
            completed: {
                amount: 0.95
            },
            name: 'Prototyping'
        }, {
            start: '2018-02-02',
            end: '2018-12-05',
            completed: {
                amount: 0.5
            },
            name: 'Development'
        }, {
            start: '2018-12-08',
            end: '2018-12-09',
            completed: {
                amount: 0.15
            },
            name: 'Testing'
        }, {
            start: '2018-12-09',
            end: '2018-12-19',
            completed: {
                amount: 0.3,
                fill: '#fa0'
            },
            name: 'Development'
        }, {
            start: '2018-12-10',
            end: '2018-12-23',
            name: 'Testing'
        }, {
            start: '2018-12-25 08:00',
            end: '2018-12-25 16:00',
            name: 'Release'
        }]
    }]
});

代码中,rangeSelector 配置快捷时间范围,navigator.enabled 显示可拖动的时间概览,scrollbar.enabled 提供平移操作。任务的 start 和 end 使用毫秒时间戳;parent 用于组织项目层级,dependency 用于连接前后任务,completed.amount 表示完成比例,取值范围为 0 到 1。

更多示例与说明:

注意:示例使用 Highcharts.ganttChart,运行环境需加载 Highcharts Gantt。

相关推荐
2分钟速写快排19 小时前
孔乙己的茴字有多少种写法?|AI 对话实时通信的三种实现
前端·javascript·github
Penge66621 小时前
JavaScript:BOM 详解
前端
Penge66621 小时前
Vite vs Webpack:前端构建工具原理与实战
前端
Penge66621 小时前
前端包管理工具:npm、Yarn、pnpm 快速入门
前端
Penge6661 天前
Sass 了解
前端
Penge6661 天前
Webpack 打包从 0 到 1 实战笔记
前端
大可不必了1 天前
03 函数定义和调用
开发语言·python
I_belong_to_jesus1 天前
C++关于分支预测的优化1
开发语言·c++·算法
Penge6661 天前
Webpack 入门:是什么、为什么需要、怎么使用?
前端
Penge6661 天前
Ant Design(Antd)了解
前端