Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:07+00:00 2026-06-14T15:16:07+00:00

I am creating a d3.js chart using a CoffeeScript class. I would like to

  • 0

I am creating a d3.js chart using a CoffeeScript class. I would like to attach a method to a click event, and then run another method depending on what was clicked:

class @Chart

  drawChart: ->
     ...

    dataArea
      .enter()
        .append("path")
          .on("click", @onClick);
     ...

  onClick: ->
    if d3.select(this).attr("type") == 'video'
      @runVideo(d3.select(this).attr("title"))

  runVideo: ->

The problem is that in the onClick method the execution context (“this”) is the selection and not the Chart class, so “runVideo is not a function.” How can I access selection attributes from within the onClick method and also run the runVideo method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:16:08+00:00Added an answer on June 14, 2026 at 3:16 pm

    What you want to do is somehow capture the this when you add the click callback.

    You have a few options here:

    // The Coffeescript way:
    .on("click", (args...) => @onClick(args...));
    
    // The jQuery way:
    .on("click", $.proxy(@onClick, @))
    
    // The ECMAscript5 way:
    .on("click", @onClick.bind(@))
    

    Then you need to fix your onClick to this:

    onClick: (evt) ->
      if d3.select(evt.target).attr("type") == 'video'
        @runVideo(d3.select(evt.target).attr("title"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done like this for creating click event handler for one part of
I am creating a chart using mxml. The mxml tags only create a chart
I'm creating an Excel chart using C++. My problem is that I want to
I'm using Jfreechart for creating charts. I'm creating BufferedImage of chart and writing it
I'm using fusioncharts free and creating some 3d pie charts like so... <div style=margin:0
I am creating a pie chart using PyChart library in Python. Here is my
I am currently using the Chart Control from System.Windows.Forms.DataVisualization to dynamically creating 10 chart
Using c# MS Excel interop library, I would like to programmatically create a new
I'm creating a custom charting control and I would like to have the possibility
Im looking for some help creating a graph using the google chart API I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.