-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Get the chart instance #81
Comments
I have exactly the same problem, would be great to have access to the Chart instance. |
If you |
Let's say I have a component with this template Now in my Same question apply if I have multiple charts in my template like that
How I can access each instance ? Hoping I'm clear enough... |
I assume you want the instance of the chart to react to some kind of event. You can extend this component. // file: your-app/components/ember-chart.js
import EmberChart from 'ember-cli-chart/components/ember-chart';
export default EmberChart.extend({
doubleClick() {
alert("DoubleClickableComponent was clicked!");
// this.get('chart') should give you the Chartjs instance.
}
}); See ember component event handlers here: https://guides.emberjs.com/v2.14.0/components/handling-events/#toc_event-names @Hugo-Contreras does this help? |
I was trying to handle an event on the Chart y-axis, so I did something like that (which is a bit ugly but working for now):
And in my component I have this method to handle the click:
Thank's for your answer ! Might help at some point. |
Would be great to have access to the chart instance without extending the component. This seems to be fairly straightforward in the unwrapped library. My need arises not from event handling, but from using callbacks. I'm creating a custom tick callback for timezone handling. I must reference the For now, I am using the hack above (thanks, Hugo!) but would be cool to have something baked in that's a little less messy. |
Thanks @hy0ug0 I have used something similar in my component that has an constructor() {
const self = this;
const chartOptions = {
onClick(e, context) {
self.handleClickEvent(e, context, self, this);
}
};
}
handleClickEvent(e, context, self, chartInstance) {
self = self || this;
if ( chartInstance ) {
const activePoints = chartInstance.getElementAtEvent(e);
if ( activePoints.length > 0 ) {
const chartElement = activePoints[0];
const datapoint = chartInstance.config.data.datasets[chartElement._datasetIndex].data[chartElement._index];
// Actions up
self.args.onclick(datapoint);
}
}
} |
I was able to have acces to the instance through another ugly hack
It works even though it definitely is not clean |
I try to get the Chart instance to be able to use the
getElementAtEvent()
method. I have this :And I want to access my Chart instance in my
handleChartClick
method, how can I do that ? The final purpose is to listen on click in axis labels and get their value.The text was updated successfully, but these errors were encountered: