如何在Highcharts甘特中的单行上制作一个绘图带?

vqlkdk9b  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(134)

我有一个甘特,我只想在特定的行上绘制一个带区。在下面的示例中,它显示在每一行上。

它可以是一个乐队情节或类似的东西(例如:SVG,酒吧,...)。只要可以控制容易的位置与开始和结束的时间,因为我会有一些超过30行在不同的位置。
这是一个fiddle
还有我的代码:

// THE CHART

Highcharts.ganttChart('container', {
  title: {
    text: 'Gantt Chart with Progress Indicators'
  },
  yAxis: {
    categories: ['1', '2']
  },
  plotOptions: {
    series: {
      dataLabels: {
        enabled: true,
        verticalAlign: "top",
        format: "{point.custom.label}"
      }
    }
  },
  xAxis: {
  plotBands: [{
      color: '#B3D1AE', // Color value
      from: Date.UTC(2014, 10, 21), // Start of the plot band
      to: Date.UTC(2014, 10, 22) // End of the plot band
    }],
  },
  series: [{
    type: 'line',
    zoneAxis: 'x',
    zones: [{
      value: Date.UTC(2014, 10, 20)
    }, {
      dashStyle: 'dot',
      value: Date.UTC(2014, 10, 25)
    }],
    data: [{
      y: 0,
      x: Date.UTC(2014, 10, 18),
      custom: {
        label: 1
      }
    }, {
      y: 0,
      x: Date.UTC(2014, 10, 25, 12),
      custom: {
        label: 2
      }
    }]
  }, {
    name: 'Project 1',
    type: 'line',
    zoneAxis: 'x',
    zones: [{
      value: Date.UTC(2014, 10, 28)
    }, {
      dashStyle: 'dot',
      value: Date.UTC(2014, 10, 29)
    }],
    data: [{
      x: Date.UTC(2014, 10, 25, 16),
      y: 0,
      custom: {
        label: 3
      }
    }, {
      x: Date.UTC(2014, 10, 29),
      y: 0,
      custom: {
        label: 4
      }
    }]
  }, {
  type: 'line',
  zoneAxis: 'x',
  data: [{
      x: Date.UTC(2014, 10, 25, 16),
      y: 1,
      custom: {
        label: 3
      }
    }, {
      x: Date.UTC(2014, 10, 29),
      y: 1,
      custom: {
        label: 4
      }
    }]
  }]
});
ibrsph3r

ibrsph3r1#

您可以使用SVG.Renderer来绘制“plotBands”,并使用axis.toPixels()方法来控制位置。

范例:

chart: {
    events: {
      load() {
        let from = this.xAxis[0].toPixels(Date.UTC(2014, 10, 21)),
          to = this.xAxis[0].toPixels(Date.UTC(2014, 10, 22)),
          width = to - from,
          rowStart = this.yAxis[0].toPixels(0.5),
          rowHeight = this.yAxis[0].toPixels(1) - this.yAxis[0].toPixels(0);

        this.renderer.rect(from, rowStart, width, rowHeight)
          .attr({
            fill: '#ff0000',
            zIndex: 0
          }).add()
      }
    }
  }

演示:https://jsfiddle.net/BlackLabel/qbo8Lmy6/
API参考资料:https://api.highcharts.com/class-reference/Highcharts.SVGRenderer https://api.highcharts.com/class-reference/Highcharts.Axis#toPixels

相关问题