0

I have the following code (using the chartkick gem):

<%= pie_chart [[t('result.positive'), @rating_positive], [t('result.negative'), @rating_negative], [t('result.neutral'), @rating_neutral]],
    colors: ['#B3D986', '#E04848', '#C9C9C9'],
    library: {
      chart: {
        backgroundColor: '#EEEEEE',
        width: 300,
        height: 250
      },
      plotOptions: {
        pie: {
          allowPointSelect: true,
          cursor: 'pointer',
          dataLabels: {
              enabled: false
          },
          showInLegend: true,
          events: {
            click: function(event, i) {
               alert("test");
            }
          }
        }
      }
    }
  %>

I just want to pas the click event function as a parameter, but rails interprets it. html_safeand helper functions are of no use. Suggestions?

4
  • "pas the click event function as a parameter, but rails interprets it" elaborate this plz Commented May 2, 2014 at 11:19
  • I got the following error: pastebin Commented May 2, 2014 at 11:30
  • event is not initalized before its being used in click: function(event, i) Commented May 2, 2014 at 11:33
  • It is working here... Commented May 2, 2014 at 11:36

1 Answer 1

2

Currently, chartkick is unable to accept functions because of the way it uses json for its parameters. I found this github discussion which discusses this. They mention a possible solution is to pass the function in as a string and then to modify how the json is deparsed similarly to this article.

Another possible solution, as I am under the impression that chartkick uses highcharts for its js, is to update the events after the page/chart has already loaded. I believe it would look something like this

$("#container").highcharts().series[0].update({
  events:{
    click: function (event, i) {
      alert(event.point.name);
    }
  }
})
Sign up to request clarification or add additional context in comments.

1 Comment

I used your update suggestion and it's working great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.