日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

highcharts中gantt甘特圖的使用

作者:前端開心果 更新時間: 2023-07-29 編程語言

示例圖:
在這里插入圖片描述
官方文檔參考:highcharts gantt
甘特圖示例
使用示例:

<template>
  <div id="container"></div>
</template>

<script>
export default {
  mounted() {
    let month = "2022-12";
    const moment = this.$moment;
    const WEEKS = {
      0: "日",
      1: "一",
      2: "二",
      3: "三",
      4: "四",
      5: "五",
      6: "六",
    };
    const data = [
      {
        name: "1#機1",
        start: new Date("2022-12-01 09:00:00").getTime(),
        end: new Date("2022-12-11 09:00:00").getTime(),
        completed: 0.25,
        y: 0,
      },
      {
        name: "1#機1",
        start: new Date("2022-12-13 09:00:00").getTime(),
        end: new Date("2022-12-18 09:00:00").getTime(),
        y: 0,
      },
      {
        name: "2#機2",
        start: new Date("2022-12-08 09:00:00").getTime(),
        end: new Date("2022-12-10 19:20:40").getTime(),
        y: 1,
      },
      {
        name: "3#機3",
        start: new Date("2022-12-06 09:00:00").getTime(),
        end: new Date("2022-12-21 09:00:00").getTime(),
        completed: {
          amount: 0.12,
          fill: "red",
        },
        y: 2,
      },
      {
        name: "4#機4",
        start: new Date("2022-12-21 09:00:00").getTime(),
        end: new Date("2022-12-31 09:00:00").getTime(),
        y: 3,
      },
    ];
    // 自定義主題
    const my_skin = {
      //顏色數組,默認從數組第一個元素取色
      // colors: [
      //   "#33FF33",
      //   "#f45b5b",
      //   "#7798BF",
      //   "#aaeeee",
      //   "#ff0066",
      //   "#eeaaee",
      //   "#55BF3B",
      //   "#DF5353",
      //   "#7798BF",
      //   "#aaeeee",
      // ],
      //背景
      chart: {
        backgroundColor: "#364766",
      },
      xAxis: {
        labels: {
          style: {
            color: "#f5f7fa",
          },
        },
      },
      yAxis: {
        title: {
          style: { color: "#f5f7fa" },
        },
        markable: { enabled: false }, //不顯示每一個點的實心
        labels: {
          style: {
            color: "#f5f7fa",
          },
        },
      },
      global: {
        useUTC: false, // 不使用utc時間
      },
      lang: {
        noData: "暫無數據",
      },
    };
    // 全局配置,需要在圖標初始化之前配置
    this.$highcharts.setOptions(my_skin, {
      global: {
        useUTC: false, // 不使用utc時間
      },
      lang: {
        noData: "暫無數據",
      },
    });
    let max = moment(this.queryForm.plan_date2).add(1, "days");
    this.$highcharts.ganttChart("container", {
      xAxis: [
        {
          min: moment(month).valueOf(),
          // max: moment(max).valueOf(), // 根據時間區間選擇
          max: moment(month).endOf("month").valueOf(), // 根據每個月選擇
          gridLineEidth: 1,
          minTickInterval: 1000 * 60 * 60 * 24,
          currentDateIndicator: true,
          tickPixelInterval: 70,
          grid: {
            borderWidth: 1, // 右側表頭邊框寬度
            cellHeight: 35, // 右側日期表頭高度
          },
          labels: {
            align: "center",
            formatter: function () {
              return `${WEEKS[moment(this.value).day()]}`;
            },
          },
        },
        {
          gridLineWidth: 1,
          minTickInterval: 1000 * 60 * 60 * 24,
          tickPixelInterval: 100,
          grid: {
            borderWidth: 1, // 右側表頭邊框寬度
            cellHeight: 30, // 右側日期表頭高度
          },
          labels: {
            align: "center",
            formatter: function () {
              return `${moment(this.value).format("M-D")} `;
            },
          },
        },
      ],
      yAxis: {
        type: "category",
        grid: {
          enabled: true,
          borderColor: "#e6e6e6",
          borderWidth: 1,
          columns: [
            {
              title: {
                text: "設備",
              },
              labels: {
                format: "{point.name}",
              },
            },
          ],
        },
      },
      tooltip: {
        formatter: function () {
          return `<div>
            設備:${this.point.name}  
            <br />
            開始時間:${moment(this.point.start).format("YYYY-MM-DD HH:mm:ss")}
            <br />
            結束時間:${moment(this.point.end).format("YYYY-MM-DD HH:mm:ss")}
          </div>`;
        },
      },
      series: [
        {
          data,
        },
      ],
      plotOptions: {
        series: {
          animation: false, // Do not animate dependency connectors
          dragDrop: {
            draggableX: false, // 橫向拖拽
            draggableY: false, // 縱向拖拽
            dragMinY: 0, // 縱向拖拽下限
            dragMaxY: 3, // 縱向拖拽上限
            dragPrecisionX: 3600000, // 橫向拖拽精度,單位毫秒
          },
          dataLabels: {
            enabled: true,
            format: "{point.name}",
            style: {
              cursor: "default",
              pointerEvents: "none",
              color: "#ffffff",
            },
          },
          allowPointSelect: true,
        },
      },
      exporting: {
        sourceWidth: 1000,
      },
      credits: {
        // 去掉右下角版權信息
        enabled: false,
      },
      chart: {
        spacingLeft: 10,
        spacingTop: 10,
      },
      pane: {
        background: [
          {
            backgroundColor: "red",
          },
        ],
      },
    });
  },
};
</script>

原文鏈接:https://blog.csdn.net/qq_38157825/article/details/128612488

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新