score:1
You can listen to the click event and then loop through all the pointLabels check if the click is in that box. If this is the case you get the corresponding label from the array containing all the labels.
Then you can open use window.location = link
or window.open(link)
to go to your link.
Example that searches the color on google on click:
const options = {
type: 'radar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'orange'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'pink'
}
]
},
options: {
onClick: (evt, activeEls, chart) => {
const {
x,
y
} = evt;
let index = -1;
for (let i = 0; i < chart.scales.r._pointLabelItems.length; i++) {
const {
bottom,
top,
left,
right
} = chart.scales.r._pointLabelItems[i];
if (x >= left && x <= right && y >= top && y <= bottom) {
index = i;
break;
}
}
if (index === -1) {
return;
}
const clickedLabel = chart.scales.r._pointLabels[index];
window.open(`https://www.google.com/search?q=color%20${clickedLabel}`); // Blocked in stack snipet. See fiddle
console.log(clickedLabel)
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
</body>
Source: stackoverflow.com
Related Query
- Chart.js turn labels into links
- Is it possible to merge duplicate labels (and their datas) into one column in Chart Js?
- Object list into chart labels not working
- Limit labels number on Chart.js line chart
- Chart.js Show labels on Pie chart
- How to add labels into Chart.js canvas plugin?
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- chart.js: Show labels outside pie chart
- Chart.js how to show cursor pointer for labels & legends in line chart
- Chart JS data labels getting cut
- How to display Line Chart dataset point labels with Chart.js?
- Making the labels responsive in chart js
- Chart.js - Draw bar chart with multiple labels
- Chart JS grouped sub labels
- Display a limited number of labels only on X-Axis of Line Chart using Chart.js
- Changing x axis labels in Chart.js line chart
- How to display data labels outside in pie chart with lines in ionic
- Line chart with large number of labels on X axis
- Center point labels between ticks (Polar Area Chart JS)
- How to align Chart.JS line chart labels to the center
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to display the labels in doughnut chart using ng2 charts?
- Chart.js Bubble chart with custome X-axis labels
- Change labels colors for radar chart js
- ChartJS: Show all labels of a mixed chart in the tooltip
- Chart.js Radar Chart How to Remove Outer Labels
- Parsing JSON data into Chart.js bar chart
- ChartJS 2.0 - Huddle labels on pie chart
- Multiple line labels for chart js
- Remove radar chart labels in chart.js
More Query from same tag
- Chart.js with React
- In Chart.js and django, add data by clicking the button
- Chart.js line chart is not displaying
- Chartjs gradient background color based on min and max values
- ChartJS set yAxes "ticks"
- Can individual bubbles in a chartjs bubble chart have labels?
- In chart.js, Is it possible to hide x-axis label/text of bar chart if accessing from mobile?
- Inserting percentage charts.js doughnut
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- Get last 6 month name in Array for Chartjs
- Template variable injection in JS script
- Enabling chartsJS bar chart to start on y axis
- How to make a chart with an associative array with chart.js?
- Chart.js, Javascript, unable to sum a data set. Javascript return NaN and I am not sure why
- Make time series show last date in axis?
- How do I fetch data from 2 tables and display into 1 chartjs
- Can I set different fill color based on a given threshold in Chart.js?
- How to represent MySQL data in the form of charts
- Overlay loading indicator before data and charts are loaded
- ChartJS does not display the legend
- destroy multiple charts on same page
- How to move the x-axis values and line points to the middle of two x-axis lines using chartjs?
- Unable to see the lines in chart.js
- How to reach to a chartjs chart's value?
- Problem with Charts.js in vue. anyone can help step by step
- Chart.js how to use scriptable options
- How to draw bars of a chart for a chart to full height?
- code works fine on jsfiddle but one function is not working on website
- Is this graph possible using chart.js?
- How to hide more than one legend on Chartjs?