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

JavaScript functions passed as string won't execute #48

Open
jdefrance-stessa opened this issue Dec 21, 2018 · 0 comments
Open

JavaScript functions passed as string won't execute #48

jdefrance-stessa opened this issue Dec 21, 2018 · 0 comments

Comments

@jdefrance-stessa
Copy link

Hi Everyone!
In this very example, trying to format y axes as well as tooltip values with currency format.
Ultimately, I also want to use JavaScript to make some of the series clickable.. etc.

As per this gem documentation, this normally is possible:

You can put anything in the options hash that Chart.js recognises. To pass a JavaScript function as an option value, wrap it in quotation marks to make it a string.

In practice, I don't seem to be able to make it work.

<div> <%= bar_chart @chart_data, { responsive: true, legend: { position: "right", }, maintainAspectRatio: false, tooltips: { mode: 'label', intersect: true, callbacks: { title: "function(tooltipItem) { return moment(tooltipItem[0].xLabel).format('ll'); }", label: "function(tooltipItem, data) { return data.datasets[tooltipItem.datasetIndex].label + ': ' + tooltipItem.yLabel; }" } }, scales: { xAxes: [{ stacked: true, }], yAxes: [{ stacked: false, userCallback: "function(value, index, values) { value = value.toString(); value = value.split(/(?=(?:...)*$)/); value = value.join(','); return '$' + value; }" }] }} %> </div>

Is this a know bug/issue?
Should I be doing this differently?

Alternatively, is there any way to access the ctx and chart variables from the generated script, so I can eventually attach these callbacks in raw JS, in the case this gem doesn't allow it?

Thanks in advance!

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

No branches or pull requests

1 participant