Skip to content
The Chat Archive
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

Highcharts.ganttChart 10.0版本 设置甘特图条行的高度

  1. User

    Highcharts.ganttChart 10.0版本 设置甘特图条行的高度

  2. Assistant

    可以通过修改barHeight属性来设置甘特图条行的高度,例如:

    Highcharts.ganttChart('container', {
        ...
        yAxis: {
            ...
            barHeight: 25 // 设置条行高度为25
            ...
        },
        ...
    });
    
  3. User

    VM18236 highcharts-gantt.js:12 Highcharts warning: Deprecated member

    • Highcharts.each: use Array.forEach
  4. Assistant

    这个是Highcharts中的警告信息,它告诉你正在使用一个已经弃用的方法 Highcharts.each,推荐使用原生的 Array.forEach 方法。在最新的Highcharts版本中,已经移除了 Highcharts.each 方法,如果你使用过时的方法,可能会导致代码在未来的版本中不兼容。

    解决方法很简单,只需要将 Highcharts.each 方法替换为原生的 Array.forEach 方法即可。例如,如果你需要遍历一个数组,可以这样写:

    var colors = ['red', 'blue', 'green'];
    
    // 使用原生的 forEach 方法遍历数组
    colors.forEach(function(color) {
        console.log(color);
    });
    

    如果你使用的是 Highcharts 的 each 方法:

    var colors = ['red', 'blue', 'green'];
    
    // 使用 Highcharts.each 方法遍历数组
    Highcharts.each(colors, function(color) {
        console.log(color);
    });
    

    那么就需要将其替换为原生的 forEach 方法:

    var colors = ['red', 'blue', 'green'];
    
    // 使用原生的 forEach 方法遍历数组
    colors.forEach(function(color) {
        console.log(color);
    });
    

    这样就可以消除这个警告了。

  5. User

    Highcharts.ganttChart 10.0版本 设置甘特图条行的高度 barHeight不起作用

  6. Assistant

    在 Highcharts Gantt 10.0 版本中,barHeight 属性不再作为 Gantt 图中条行高度的唯一属性。取而代之的是 pointHeight 和 barHeight 属性的组合。pointHeight 属性用于设置整个甘特图中所有图表点的高度,而 barHeight 属性则用于设置单个甘特图中条行的高度。

    要设置条行高度,请将 barHeight 属性与点配置对象中的 height 属性一起使用,例如:

    Highcharts.ganttChart('container', {
        chart: {
            type: 'gantt'
        },
        ...
        plotOptions: {
            gantt: {
                pointHeight: 30, // 设置所有条行的高度
                dataLabels: {
                    enabled: true
                },
                bar: {
                    height: 20 // 设置单个条行的高度
                }
            }
        },
        ...
    });
    

    在上面的示例中,pointHeight 属性设置了所有条行的高度,而 bar.height 属性设置单个条行的高度。注意,pointHeight 和 bar.height 的单位都是像素。