Search code examples
javascriptplotlyplotly.js

Add more data to the tooltip on the chart with Plotly


I want to add more data to the tooltip, but it only show %{customdata[0]} ... instead of the value

I used customdata as below, but it not work.

{
    "name": "PARAM01_STEP_MEAN",
    "type": "scatter",
    "x": [
        "2024-07-05 08:48:35",
        "2024-07-05 08:48:46"
    ],
    "y": [
        "202.072",
        "195.636"
    ],
    "customdata": [
        [
            "LOT_20240705084818519",
            "LOT_20240705084818519"
        ],
        [
            "WF#1",
            "WF#1"
        ],
        [
            "RCP#_01",
            "RCP#_01"
        ],
        [
            "2",
            "1"
        ]
    ],
    "hovertemplate": "<span>Sum Param: PARAM01_STEP_MEAN</span><br>\n<span>Sum Time: %{x}<span><br>\n<span>Lot ID: %{customdata[0]}</span></br>\n<span>Wafer ID: %{customdata[1]}</span></br>\n<span>Recipe ID: %{customdata[2]}</span></br>\n<span>Step ID: %{customdata[3]}</span></br>\n<span>Value: %{y}</span>\n<extra></extra>"
}

Solution

  • There are 2 points in your data and you want to show additional information for each of these 2 points, so customdata should contain 2 arrays as well :

        "customdata": [
            [
                // point(x[0], y[0])
                "LOT_20240705084818519",   // customdata[0]
                "WF#1",                    // customdata[1]
                "RCP#_01",                 // customdata[2]
                "2"                        // customdata[3]
            ],
            [
                // point(x[1], y[1])
                "LOT_20240705084818519",   // customdata[0]
                "WF#1",                    // customdata[1]
                "RCP#_01",                 // customdata[2]
                "1"                        // customdata[3]
            ]
        ],