Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add link to point or label #4639

Closed
zecka opened this issue Aug 9, 2017 · 7 comments
Closed

[FEATURE] Add link to point or label #4639

zecka opened this issue Aug 9, 2017 · 7 comments

Comments

@zecka
Copy link

zecka commented Aug 9, 2017

Hello,

Is there any way to add a link on a point of a line chart ?

@etimberg
Copy link
Member

etimberg commented Aug 9, 2017

@zeckart what kind of link are you looking to add?

@zecka
Copy link
Author

zecka commented Aug 9, 2017

@etimberg a link to an other page

@rmaksim
Copy link

rmaksim commented Aug 9, 2017

@zeckart see http://www.chartjs.org/docs/latest/general/interactions/events.html#events and http://www.chartjs.org/docs/latest/developers/api.html#getelementsatevente

code example:

var cv = document.getElementById('chartJSContainer')
var ctx = cv.getContext('2d');
var chart = new Chart(ctx, options);
cv.onclick = function(evt){
    var activePoint = chart.getElementAtEvent(evt);
    console.log('activePoint', activePoint)
    // var url = ... make link with data from activePoint
    window.location = 'https://www.google.by/search?q=chart+js+events&oq=chart+js+events'
};

@etimberg
Copy link
Member

etimberg commented Aug 9, 2017

@rmaksim's answer has the best solution. Since everything is on canvas, you'll need to do the hit detection yourself.

@zecka
Copy link
Author

zecka commented Aug 10, 2017

Thank's a lot for your help I'm done with that, here is a fiddle:
https://jsfiddle.net/zecka/51w5ttwz/

@vabiro
Copy link

vabiro commented Dec 26, 2019

Sorry to be a bother, but has this been integrated into ChartJs?
I have tried the above example in Chrome Version 79.0.3945.88 and no joy.

It would be great if there was an easy way to associate a point in chart with a url anchor. Even better if we could create a generic code from the point that would be a value in the url.

Is there any hope of this?

@sjurgis
Copy link

sjurgis commented May 24, 2022

Note - the method has been renamed from getElementAtEvent to getElementsAtEventForMode in v3

https://github.com/chartjs/Chart.js/blob/a7d98fb1a0c0496cf87705351eb5995fd0e950af/docs/getting-started/v3-migration.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants