score:0
You can calculate if the mouse is in the area by getting the value of the y axis, index of the x axis and then calculate the max fill and then check if the yVal is lower as that:
var chart_canvas = document.getElementById("myChart");
var stackedLine = new Chart(chart_canvas, {
type: 'line',
data: {
labels: ["0.0", "0.2", "0.4", "0.6", "0.8", "1.0"],
fill: true,
datasets: [{
label: 'Usage',
pointRadius: 3,
data: [.5, .3, .2, .1, .4, .3],
borderWidth: 1,
fill: true
}, {
label: 'Popularity',
pointRadius: 3,
data: [.0, .1, .2, .4, .1, .4],
borderWidth: 1,
fill: true
}]
},
options: {
scales: {
y: {
stacked: true,
}
},
onHover: (evt, activeEls, chart) => {
let yVal = chart.scales.y.getValueForPixel(evt.y);
let index = chart.scales.x.getValueForPixel(evt.x);
let maxFilledArea = chart.data.datasets.reduce((acc, curr) => (acc + curr.data[index]), 0)
if (yVal <= maxFilledArea) {
console.log('Mouse in filled area')
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
<main>
<canvas id="myChart" width="500" height="500"></canvas>
</main>
Source: stackoverflow.com
Related Query
- Hover/click area in filled line chart in chart.js
- How to add an on click event to my Line chart using Chart.js
- chartjs show dot point on hover over line chart
- Draw a horizontal and vertical line on mouse hover in chart js
- ChartJs line chart - display permanent icon above some data points with text on hover
- Chart.js line chart with area range
- Click event of stacked line chart not working
- How to add area with break on line chart with fill color
- Background-color for area below line chart in chartJs?
- Want only line not area under it in chart js
- how to highlight a specific area on chartjs line chart
- How to change the chart line or area colors according to the user need?
- How to customize tooltip on mouse hover of a polar area chart of Angular Charts
- Chart Js Line chart with fill on click with full information of its legend text
- Chart js how to toggle line without click
- How to plot a line chart which has both the start and points outside the canvas area using Chart.js
- Chart.js line chart looking as area chart with smooth lines but not sharp
- data in charts of charts.js is changing when I click in the line chart
- Drawing a horizontal line on a stacked bar chart on hover (chart js)
- How to limit chart JS hover to take only one value from each line chart when zoomed out?
- Line chart Change background color of shaded region on hover (Chartjs)
- Can we remove bar chart line on click on pie chart legend label?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Limit labels number on Chart.js line chart
- Chart.js - How to set a line chart dataset as disabled on load
- Chart Js Change Label orientation on x-Axis for Line Charts
- Chart area background color chartjs
- Draw horizontal line on chart in chart.js on v2
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Remove the vertical line in the chart js line chart
More Query from same tag
- Is There any way to show image on top of the stacked bar, Am getting image on every color Instead of that i need only on top of each bar
- Loop through multiple rows as labels and data in chart.js and PHP
- How can i add additional Data(Type) to chart.js
- How to set the serifs on the X and Y axes?
- chart.js v3 - data decimation not working with zoom plugin
- How to use a string returned from php by ajax as data for a chart.js chart?
- ChartJS line chart drag and zoom
- Put JSON data into chart.js pie chart
- chart.js bar chart color change based on value
- Converting JSON data into Chart.js array from strings
- Is there a JavaScript Method/ Function to loop Objects via Keys into a array?
- Angular chart how to show the legend data value by default along with legend name
- Overlapping Bar Chart using Chart.js
- VueJS TypeScript using ChartJS - Parsing error: '}' expected
- Feeding PHP MySQL Call into Charts.js
- Angular charts is not displayed
- Displaying JSON data with Chartjs
- Tilting the labels of the x axis to some degrees in chart.js
- Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. chat.JS
- Can't trigger beforeDraw with Vue-Chartjs (or any other plugins)
- How to update data Chart in async way in Angular Chart.js?
- Changing chart data dynamically with C# from SQL database
- chart.js not working in browser with django. no error for template and static folder setting
- How to edit my custom tooltips in my line chart using chart.js?
- Is there any way I can customize my chartjs
- Using a prepared dataset in chart.js
- How to use computed property with data from JSON in data object for time axis in Vue using Chart.js
- using data structures in chartjs
- How to export report as PDF/CSV in ChartNew.js
- show text in both y axis in dual axis chart js