|
@@ -1629,6 +1629,21 @@ function createChart(chartType, data, labels) {
|
|
|
display: false,
|
|
|
fullSize: true,
|
|
|
position: 'bottom',
|
|
|
+ onClick: function (e, legendItem, legend) {
|
|
|
+ e.native.stopImmediatePropagation();
|
|
|
+ // 獲取被點擊的數據集索引
|
|
|
+ selectedDatasetIndex = legendItem.datasetIndex;
|
|
|
+
|
|
|
+
|
|
|
+ const dataset_color = legend.chart.data.datasets[selectedDatasetIndex].borderColor;
|
|
|
+ console.log(dataset_color)
|
|
|
+
|
|
|
+ colorInput.value = dataset_color;
|
|
|
+
|
|
|
+ // // 手動觸發 Chart.js 的默認圖例點擊事件
|
|
|
+ // const defaultClickHandler = Chart.defaults.plugins.legend.onClick;
|
|
|
+ // defaultClickHandler.call(this, e, legendItem, legend);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
},
|
|
@@ -1692,7 +1707,6 @@ function createChart(chartType, data, labels) {
|
|
|
}
|
|
|
},
|
|
|
onClick: function (event, elements) {
|
|
|
- console.log()
|
|
|
if (elements.length > 0) {
|
|
|
const element = elements[0];
|
|
|
selectedDatasetIndex = element.datasetIndex;
|