iT邦幫忙

0

請問 JS 如何做到同一個 bar 可以多次顯示同個狀態?

  • 分享至 

  • xImage

請問 JS 如何做到同一個 bar 可以多次顯示同個狀態?
如下圖,目前困難點是找到的套件通常只有狀態合計不能有拆分

現在能做到

期望效果

目前使用套件、代碼:
https://www.chartjs.org/docs/latest/charts/bar.html

數據結構

{
    "success": true,
    "code": 1000,
    "message": "操作成功!",
    "totalItems": 5,
    "data": [
        {
            "machineNo": "C01",
            "oeeDetailVOS": [
                {
                    "startTime": 1687622400000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "77730",
                    "waitReason": null
                },
                {
                    "startTime": 1687700130000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "169",
                    "waitReason": null
                },
                {
                    "startTime": 1687700299000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "4860",
                    "waitReason": null
                },
                {
                    "startTime": 1687705159000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "137",
                    "waitReason": null
                },
                {
                    "startTime": 1687705296000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "3504",
                    "waitReason": null
                }
            ],
            "oeeProportionVOS": [
                {
                    "color": "001",
                    "duration": "306",
                    "proportion": "0.35"
                },
                {
                    "color": "010",
                    "duration": "86094",
                    "proportion": "99.65"
                },
                {
                    "color": "100",
                    "duration": "0",
                    "proportion": "0.00"
                },
                {
                    "color": "000",
                    "duration": "0",
                    "proportion": "0.00"
                }
            ]
        },
        {
            "machineNo": "C02",
            "oeeDetailVOS": [
                {
                    "startTime": 1687622400000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "25184",
                    "waitReason": null
                },
                {
                    "startTime": 1687647584000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "698",
                    "waitReason": null
                },
                {
                    "startTime": 1687648282000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "60518",
                    "waitReason": null
                }
            ],
            "oeeProportionVOS": [
                {
                    "color": "001",
                    "duration": "85702",
                    "proportion": "99.19"
                },
                {
                    "color": "010",
                    "duration": "698",
                    "proportion": "0.81"
                },
                {
                    "color": "100",
                    "duration": "0",
                    "proportion": "0.00"
                },
                {
                    "color": "000",
                    "duration": "0",
                    "proportion": "0.00"
                }
            ]
        },
        {
            "machineNo": "C03",
            "oeeDetailVOS": [
                {
                    "startTime": 1687622400000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "4456",
                    "waitReason": null
                },
                {
                    "startTime": 1687626856000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "49",
                    "waitReason": null
                },
                {
                    "startTime": 1687626905000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "18109",
                    "waitReason": null
                },
                {
                    "startTime": 1687645014000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "7",
                    "waitReason": null
                },
                {
                    "startTime": 1687645021000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "20923",
                    "waitReason": null
                },
                {
                    "startTime": 1687665944000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "26",
                    "waitReason": null
                },
                {
                    "startTime": 1687665970000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "161",
                    "waitReason": null
                },
                {
                    "startTime": 1687666131000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "1",
                    "waitReason": null
                },
                {
                    "startTime": 1687666132000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "28501",
                    "waitReason": null
                },
                {
                    "startTime": 1687694633000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "34",
                    "waitReason": null
                },
                {
                    "startTime": 1687694667000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "14133",
                    "waitReason": null
                }
            ],
            "oeeProportionVOS": [
                {
                    "color": "001",
                    "duration": "86283",
                    "proportion": "99.86"
                },
                {
                    "color": "010",
                    "duration": "117",
                    "proportion": "0.14"
                },
                {
                    "color": "100",
                    "duration": "0",
                    "proportion": "0.00"
                },
                {
                    "color": "000",
                    "duration": "0",
                    "proportion": "0.00"
                }
            ]
        },
        {
            "machineNo": "C04",
            "oeeDetailVOS": [
                {
                    "startTime": 1687622400000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "31302",
                    "waitReason": null
                },
                {
                    "startTime": 1687653702000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "19",
                    "waitReason": null
                },
                {
                    "startTime": 1687653721000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "25062",
                    "waitReason": null
                },
                {
                    "startTime": 1687678783000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "399",
                    "waitReason": null
                },
                {
                    "startTime": 1687679182000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "8226",
                    "waitReason": null
                },
                {
                    "startTime": 1687687408000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "21392",
                    "waitReason": null
                }
            ],
            "oeeProportionVOS": [
                {
                    "color": "001",
                    "duration": "64590",
                    "proportion": "74.76"
                },
                {
                    "color": "010",
                    "duration": "21810",
                    "proportion": "25.24"
                },
                {
                    "color": "100",
                    "duration": "0",
                    "proportion": "0.00"
                },
                {
                    "color": "000",
                    "duration": "0",
                    "proportion": "0.00"
                }
            ]
        },
        {
            "machineNo": "C05",
            "oeeDetailVOS": [
                {
                    "startTime": 1687622400000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "32359",
                    "waitReason": null
                },
                {
                    "startTime": 1687654759000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "635",
                    "waitReason": null
                },
                {
                    "startTime": 1687655394000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "29413",
                    "waitReason": null
                },
                {
                    "startTime": 1687684807000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "21209",
                    "waitReason": null
                },
                {
                    "startTime": 1687706016000,
                    "machineStatusEnum": {
                        "machineState": 4,
                        "machineStateName": "運行"
                    },
                    "duration": "129",
                    "waitReason": null
                },
                {
                    "startTime": 1687706145000,
                    "machineStatusEnum": {
                        "machineState": 3,
                        "machineStateName": "等待"
                    },
                    "duration": "2655",
                    "waitReason": null
                }
            ],
            "oeeProportionVOS": [
                {
                    "color": "001",
                    "duration": "61901",
                    "proportion": "71.64"
                },
                {
                    "color": "010",
                    "duration": "24499",
                    "proportion": "28.36"
                },
                {
                    "color": "100",
                    "duration": "0",
                    "proportion": "0.00"
                },
                {
                    "color": "000",
                    "duration": "0",
                    "proportion": "0.00"
                }
            ]
        }
    ]
}
看更多先前的討論...收起先前的討論...
pickuse iT邦新手 3 級 ‧ 2023-06-29 10:36:52 檢舉
https://segmentfault.com/q/1010000043947790
你是搬運工嗎?
knvbhk iT邦新手 5 級 ‧ 2023-06-29 10:50:15 檢舉
可否post 一下你的code 呢? (跟那邊的回復一樣 8)),因為你的問題問得不清楚,又不明確。
傻眼,搬這個做什麼?
小MIS iT邦研究生 1 級 ‧ 2023-06-29 11:35:16 檢舉
那個是我,何來搬運?
pickuse iT邦新手 3 級 ‧ 2023-06-29 11:39:44 檢舉
原來如此,我想說怎麼可以查到一樣的文章
pickuse iT邦新手 3 級 ‧ 2023-06-29 11:44:03 檢舉
首先你要確定你要做的功能是統計圖,才適合用這個套件,如果不是的話我會選擇自己用表格兜一個
greenriver iT邦研究生 4 級 ‧ 2023-06-29 13:10:24 檢舉
用堆疊法就可以辦到,
https://www.chartjs.org/docs/latest/samples/bar/stacked.html,
按照你給的圖,條件每個長條圖都是0到24格,每格都有各自顏色,
思路是:一個bar,要分成24個資料(要注意堆疊的排列順序),每個資料分別給顏色,堆疊起來就可以了。
缺點是,很麻煩,有可能要自己將整包資料重新整理。
@pickuse
感謝你提供了這個網頁,我就想說開版的為什麼有時候會簡體繁體夾雜著問,原來是這個緣故啊,科科。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答