当前位置: 首页 > article >正文

Highcharts甘特图基本用法(highcharts-gantt.js)

参考官方文档:

https://www.highcharts.com/docs/gantt/getting-started-gantt

https://www.highcharts.com/demo/gantt/project-management

 https://www.hcharts.cn/demo/gantt

链接在下面按需引入

https://code.highcharts.com/gantt/highcharts-gantt.js

https://code.highcharts.com/highcharts.js

https://code.highcharts.com/gantt/modules/gantt.js

JS初始化举例:

const day = 24 * 36e5,
        today = Math.floor(Date.now() / day) * day;

    const options = {
        chart: {
            plotBackgroundColor: 'rgba(128,128,128,0.02)',
            plotBorderColor: 'rgba(128,128,128,0.1)',
            plotBorderWidth: 1
        },

        plotOptions: {
            series: {
                borderRadius: '50%',
                connectors: {
                    dashStyle: 'ShortDot',
                    lineWidth: 2,
                    radius: 5,
                    startMarker: {
                        enabled: false
                    }
                },
                groupPadding: 0,
                dataLabels: [{
                    enabled: true,
                    align: 'left',
                    format: '{point.name}',
                    padding: 10,
                    style: {
                        fontWeight: 'normal',
                        textOutline: 'none'
                    }
                }, {
                    enabled: true,
                    align: 'right',
                    format: '{#if point.completed}{(multiply ' +
                        'point.completed.amount 100):.0f}%{/if}',
                    padding: 10,
                    style: {
                        fontWeight: 'normal',
                        textOutline: 'none',
                        opacity: 0.6
                    }
                }]
            }
        },

        series: [{
            name: 'Offices',
            data: [{
                name: 'New offices',
                id: 'new_offices',
                owner: 'Peter'
            }, {
                name: 'Prepare office building',
                id: 'prepare_building',
                parent: 'new_offices',
                start: today - (2 * day),
                end: today + (6 * day),
                completed: {
                    amount: 0.2
                },
                owner: 'Linda'
            }, {
                name: 'Inspect building',
                id: 'inspect_building',
                dependency: 'prepare_building',
                parent: 'new_offices',
                start: today + 6 * day,
                end: today + 8 * day,
                owner: 'Ivy'
            }, {
                name: 'Passed inspection',
                id: 'passed_inspection',
                dependency: 'inspect_building',
                parent: 'new_offices',
                start: today + 9.5 * day,
                milestone: true,
                owner: 'Peter'
            }, {
                name: 'Relocate',
                id: 'relocate',
                dependency: 'passed_inspection',
                parent: 'new_offices',
                owner: 'Josh'
            }, {
                name: 'Relocate staff',
                id: 'relocate_staff',
                parent: 'relocate',
                start: today + 10 * day,
                end: today + 11 * day,
                owner: 'Mark'
            }, {
                name: 'Relocate test facility',
                dependency: 'relocate_staff',
                parent: 'relocate',
                start: today + 11 * day,
                end: today + 13 * day,
                owner: 'Anne'
            }, {
                name: 'Relocate cantina',
                dependency: 'relocate_staff',
                parent: 'relocate',
                start: today + 11 * day,
                end: today + 14 * day
            }]
        }, {
            name: 'Product',
            data: [{
                name: 'New product launch',
                id: 'new_product',
                owner: 'Peter'
            }, {
                name: 'Development',
                id: 'development',
                parent: 'new_product',
                start: today - day,
                end: today + (11 * day),
                completed: {
                    amount: 0.6,
                    fill: '#e80'
                },
                owner: 'Susan'
            }, {
                name: 'Beta',
                id: 'beta',
                dependency: 'development',
                parent: 'new_product',
                start: today + 12.5 * day,
                milestone: true,
                owner: 'Peter'
            }, {
                name: 'Final development',
                id: 'finalize',
                dependency: 'beta',
                parent: 'new_product',
                start: today + 13 * day,
                end: today + 17 * day
            }, {
                name: 'Launch',
                dependency: 'finalize',
                parent: 'new_product',
                start: today + 17.5 * day,
                milestone: true,
                owner: 'Peter'
            }]
        }],
        tooltip: {
            pointFormat: '<span style="font-weight: bold">{point.name}</span><br>' +
                '{point.start:%e %b}' +
                '{#unless point.milestone} → {point.end:%e %b}{/unless}' +
                '<br>' +
                '{#if point.completed}' +
                'Completed: {multiply point.completed.amount 100}%<br>' +
                '{/if}' +
                'Owner: {#if point.owner}{point.owner}{else}unassigned{/if}'
        },
        title: {
            text: 'Gantt Project Management'
        },
        xAxis: [{
            currentDateIndicator: {
                color: '#2caffe',
                dashStyle: 'ShortDot',
                width: 2,
                label: {
                    format: ''
                }
            },
            dateTimeLabelFormats: {
                day: '%e<br><span style="opacity: 0.5; font-size: 0.7em">%a</span>'
            },
            grid: {
                borderWidth: 0
            },
            gridLineWidth: 1,
            min: today - 3 * day,
            max: today + 18 * day,
            custom: {
                today,
                weekendPlotBands: true
            }
        }],
        yAxis: {
            grid: {
                borderWidth: 0
            },
            gridLineWidth: 0,
            labels: {
                symbol: {
                    width: 8,
                    height: 6,
                    x: -4,
                    y: -2
                }
            },
            staticScale: 30
        },
        accessibility: {
            keyboardNavigation: {
                seriesNavigation: {
                    mode: 'serialize'
                }
            },
            point: {
                descriptionFormatter: function (point) {
                    const completedValue = point.completed ?
                        point.completed.amount || point.completed : null,
                        completed = completedValue ?
                            ' Task ' + Math.round(completedValue * 1000) / 10 +
                            '% completed.' :
                            '',
                        dependency = point.dependency &&
                            point.series.chart.get(point.dependency).name,
                        dependsOn = dependency ?
                            ' Depends on ' + dependency + '.' : '';

                    return Highcharts.format(
                        point.milestone ?
                            '{point.yCategory}. Milestone at {point.x:%Y-%m-%d}. ' +
                            'Owner: {point.owner}.{dependsOn}' :
                            '{point.yCategory}.{completed} Start ' +
                            '{point.x:%Y-%m-%d}, end {point.x2:%Y-%m-%d}. Owner: ' +
                            '{point.owner}.{dependsOn}',
                        { point, completed, dependsOn }
                    );
                }
            }
        },
        lang: {
            accessibility: {
                axis: {
                    xAxisDescriptionPlural: 'The chart has a two-part X axis ' +
                        'showing time in both week numbers and days.'
                }
            }
        }
    };

    // Plug-in to render plot bands for the weekends
    Highcharts.addEvent(Highcharts.Axis, 'foundExtremes', e => {
        if (e.target.options.custom && e.target.options.custom.weekendPlotBands) {
            const axis = e.target,
                chart = axis.chart,
                day = 24 * 36e5,
                isWeekend = t => /[06]/.test(chart.time.dateFormat('%w', t)),
                plotBands = [];

            let inWeekend = false;

            for (
                let x = Math.floor(axis.min / day) * day;
                x <= Math.ceil(axis.max / day) * day;
                x += day
            ) {
                const last = plotBands.at(-1);
                if (isWeekend(x) && !inWeekend) {
                    plotBands.push({
                        from: x,
                        color: {
                            pattern: {
                                path: 'M 0 10 L 10 0 M -1 1 L 1 -1 M 9 11 L 11 9',
                                width: 10,
                                height: 10,
                                color: 'rgba(128,128,128,0.15)'
                            }
                        }
                    });
                    inWeekend = true;
                }

                if (!isWeekend(x) && inWeekend && last) {
                    last.to = x;
                    inWeekend = false;
                }
            }
            axis.options.plotBands = plotBands;
        }
    });
    Highcharts.ganttChart('container', options);//container这里是div的id


http://www.kler.cn/a/314127.html

相关文章:

  • 如何在 Ubuntu 上 部署 OceanBase
  • MFC程序崩溃时生成dmp文件
  • 昆明华厦眼科医院举办中外专家眼科技术研讨会
  • 【项目组件】第三方库——websocketpp
  • llama factory lora 微调 qwen2.5 7B Instruct模型
  • Java 多线程(三)—— 死锁
  • 安装黑群晖系统,并使用NAS公网助手访问教程(好文)
  • 【系统架构设计师】虚拟机架构风格
  • 十五、差分输入运算放大电路
  • C++——模板初阶
  • 网页聊天——测试报告——Selenium自动化测试
  • 分类预测|2024年最新优化算法鹦鹉优化器PO|基于鹦鹉优化SVM支持向量机数据分类预测Matlab程序PO-SVM
  • 2024年9月python二级易错题和难题大全(附详细解析)(五)
  • allWebPlugin中间件自定义alert、confirm及prompt使用
  • 力扣1143-最长公共子序列(Java详细题解)
  • 分布式光伏发电系统如何确保电能质量达到并网要求?
  • Tiny-universe学习笔记1:Qwen-blog
  • 数据飞轮:打造业务增长的持续循环
  • C++——string的了解和使用
  • 相见恨晚的一本书《纳瓦尔宝典:财富与幸福指南》
  • 内网渗透- 内网渗透的基本知识
  • 【物联网】时序数据库InfluxDB解析及1.x版本与2.x版本区别详解
  • Docker 笔记
  • java计算字符串中大写字母的个数
  • 30道常见的软件测试面试题(含答案+文档)
  • 【若依框架】按时间查询数据的操作