การเข้าถึงข้อมูลใน Tooltip :
การอ้างอิงถึง ในระดับต่างๆ เช่นระดับ dataset ซึ่งจะเป็นชุดข้อมูล Array จะอ้างอิงถึงชุดข้อมูลด้วยตัวชี้
tooltipItem.datasetIndex ส่วนการเข้าถึง Element ใน Array ตะต้องใช้ตัวชี้ tooltipItem.dataIndex
ตัวอย่าง :
options: {
plugins: { tooltip: { callbacks: { label: function(tooltipItem, data) { // Access the tooltip item index var datasetIndex = tooltipItem.datasetIndex; // Access the index of the hovered element within the dataset var index = tooltipItem.dataIndex; // Access the dataset var dataset = data.datasets[datasetIndex]; // Access the data value at the specified index var dataValue = dataset.data[index]; // Do something with the data value return dataValue; } } } } }
ไม่มีความคิดเห็น:
แสดงความคิดเห็น