score:0
Try using mouseover
and mouseout
as shown below. Similarly you can also use mouseenter
and mouseleave
methods to handle events.
$("#chart1").mouseover(function(e) {
var activeBars = chart1.getPointsAtEvent(e);
activeBars[0].display = true;
chart1.update();
});
$("#chart1").mouseout(function(e) {
var activeBars = chart1.getPointsAtEvent(e);
activeBars[0].display = false;
chart1.update();
});
score:1
$("#chart1").mouseover(function(e) {
chart1.datasets[0].points[0].display = true;
chart1.update();
});
$("#chart1").mouseout(function(e) {
chart1.datasets[0].points[0].display = false;
chart1.update();
});
score:5
Edit: The following solution is for Chart.js v1.0.2 (the latest version at the time this solution was proposed). Please refer to this answer which provides a solution for Chart.js v2.x.x.
I ran into a similar situation a while back and resolved this by making the default point dot "invisible" as follows:
- setting pointDotRadius to 1
- setting pointStrokeColor to white with the alpha set to 0
The two steps above make the default point dot very small, this, in combination with the transparent point stroke, makes the default point dot invisible. Now if we make the pointDotStrokeWidth large enough, we can achieve the desired hover effect. i.e.
- set pointDotStrokeWidth to a larger value (I used 8)
- set the desired values for pointColor, pointHighlightFill, pointHighlightStroke
[Note: the same effect can be achieved by making pointColor transparent but if you are plotting multiple datasets, then the tooltip wouldn't show the corresponding line color next to the data value.]
Example below (or you can checkout this Fiddle: ChartJS - Show Points on Hover):
var data = {
labels: ["Point0", "Point1", "Point2", "Point3", "Point4"],
datasets: [
{
label: "My Chart",
fillColor: "rgba(87, 167, 134, 0.2)",
strokeColor: "rgba(87, 167, 134, 1)",
pointColor: "rgba(87, 167, 134, 1)",
pointStrokeColor: "rgba(255, 255, 255, 0)",
pointHighlightFill: "rgba(87, 167, 134, 0.7)",
pointHighlightStroke: "rgba(87, 167, 134, 1)",
data: [5, 39, 109, 19, 149]
}
]
};
var ctx = document.getElementById("my_chart").getContext("2d");
myChart = new Chart(ctx).Line(data, {
responsive : true,
bezierCurve: false,
datasetFill: true,
pointDotRadius: 1,
pointDotStrokeWidth: 8,
pointHitDetectionRadius: 20,
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<canvas id="my_chart"></canvas>
score:12
Tested with Chart.js v2.6.0
Global setting will do the trick:
Chart.defaults.global.hover.intersect = false;
Or directly in chart config:
options: {
hover: {
intersect: false;
}
}
And point settings for dataset.
- initial color of the point should be transparent
- hover color must be set to the desired color
e.g.
datasets: [{
label: 'My First dataset',
borderColor: 'rgb(255, 99, 132)',
backgroundColor: 'rgb(255, 99, 132)',
data: [10, 30, 46, 2, 8, 50, 0],
fill: false,
pointBorderColor: 'rgba(0, 0, 0, 0)',
pointBackgroundColor: 'rgba(0, 0, 0, 0)',
pointHoverBackgroundColor: 'rgb(255, 99, 132)',
pointHoverBorderColor: 'rgb(255, 99, 132)'}],...
window.onload = function() {
const mode = 'index';
const intersect = false;
const config = {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First dataset',
borderColor: 'rgb(255, 99, 132)',
backgroundColor: 'rgb(255, 99, 132)',
data: [10, 30, 46, 2, 8, 50, 0],
fill: false,
pointBorderColor: 'rgba(0, 0, 0, 0)',
pointBackgroundColor: 'rgba(0, 0, 0, 0)',
pointHoverBackgroundColor: 'rgb(255, 99, 132)',
pointHoverBorderColor: 'rgb(255, 99, 132)',
}, {
label: 'My Second dataset',
borderColor: 'rgb(54, 162, 235)',
backgroundColor: 'rgb(54, 162, 235)',
data: [7, 49, 46, 13, 25, 30, 22],
fill: false,
pointBorderColor: 'rgba(0, 0, 0, 0)',
pointBackgroundColor: 'rgba(0, 0, 0, 0)',
pointHoverBackgroundColor: 'rgb(54, 162, 235)',
pointHoverBorderColor: 'rgb(54, 162, 235)',
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Mode: index, intersect = false'
},
tooltips: {
mode: 'index',
intersect: intersect,
},
hover: {
mode: mode,
intersect: intersect
},
}
};
const ctx = document.getElementById('canvas').getContext('2d');
const chart = new Chart(ctx, config);
}
<canvas id="canvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
Source: stackoverflow.com
Related Query
- chartjs show dot point on hover over line chart
- show label in tooltip but not in x axis for chartjs line chart
- ChartJs line chart repaint glitch while hovering over
- Show data dynamically in line chart - ChartJS
- Chartjs - show elements in all datasets on hover using bar chart
- ChartJS - Line chart issue with only 1 point
- ChartJs line chart - display permanent icon above some data points with text on hover
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Adding line over stacked line chart with ChartJS
- Empty circle - only point strok in line chart for ChartJS
- chartjs show 24 hours in line chart
- plot a point on top on line chart in chartjs
- Show label for every data point in line chart
- chartjs hover over data without hoveringing on line
- Chartjs line graph point hover animation buggy / jumpy
- Chartjs sample line chart setup doesn't show dataLabels
- Moving vertical line when hovering over the chart using chart.js
- line chart with {x, y} point data displays only 2 values
- Chart.js how to show cursor pointer for labels & legends in line chart
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How to display Line Chart dataset point labels with Chart.js?
- ChartJS Line Graph - Multiple Lines, Show one Value on Tooltip
- Detecting hover events over parts of a chart using Chart.js
- Change point size and color on hover in chartjs
- how to show multiple values in point hover using chart.js
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- How to render a vertical line on hover in chartjs
- Draw a horizontal and vertical line on mouse hover in chart js
- ChartJS - Line Chart with different size datasets
More Query from same tag
- How can I fasten up the Chart.js graph generation from JQuery over PHP and mySQL?
- Radar chart - show values near vertices in chart.js
- How to get a square grid in Chart.js with responsive scatter chart?
- How to decrease the barthickness in ng2-charts?
- how to change object properties by on-click
- Python list does not work in django with ChartJS
- Render pie chart datasets out of 100% -- Chart.JS
- Chart.js runs in JSFiddle but not local "Chart is not defined"
- js error: while trying to display graph using chart.js: Uncaught TypeError: Cannot read property 'call' of undefined
- Chart.js horizontal line chart or modified horizontal bar chart
- How i can localize days and month name in ChartJS 3.x?
- Angular-Chart.js - Tooltip not working with 0 values
- Include Percentage In Legend
- use ng2-charts with a loader and AfterViewInit
- How can I remove the white border from Chart.js V2.6.0 pie chart?
- Line Chart x-Axis datapoints with Strings
- How can I calculate a value and place it inside the last bar in a Chart.JS bar chart?
- Apply/Register conflicting plugins to different charts
- Chart.js passing value data dynamic
- Chart.js V2: Add prefix or suffix to tooltip label
- hereChartJS Line Chart with Time Axis
- Need help styling chart JS Radar chart
- Getting clicked object from each section of a single stack bar as my stack bar has multiple sections Chart.js
- ChartJS ignoring TailwindCSS styling
- JavaScript ignore commas inside ChartJS data field pulled from csv that data has commas and is enclosed by double quotes
- Dynamic dataset from MySQL query with Chart.js
- how to use chartjs-plugin-crosshair in Angular 6+?
- How do I make an interactive line chart
- Get bar value when onClick Reactjs
- Chart.js: How can a line series (out of many) change line color and thickness upon mouse hover?