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 9032343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:57:35+00:00 2026-06-16T07:57:35+00:00

Using d3, I have some simple markup like this: <div id=my-log></div> I have an

  • 0

Using d3, I have some simple markup like this:

<div id="my-log"></div>

I have an object that uses d3 to render. I’ve got a number of these that draw charts and graphs, but this one just prints a log.

Here’s the code:

class Log

  # Run on DOM Ready
  constructor: (selector,data) ->
    @s = selector
    @data = data || this.mockData()
    this.setup()
    this.draw()

  # Append a message onto the end of the log. Optionally shift the first point off.
  pushData: (message, shift = false) ->
    @data.push message
    @data.shift() if shift
    this.update()

  mockData: ->
    [{
      sender: 'tester',
      message: 'foo bar baz'
    }]

  template: (data) ->
    """
    <div class="sender">#{data.sender}</div>
    <div class="message">#{data.message}</div>
    """

  setup: ->
    @container = d3.select(@s).append('ul').attr('class','log')

  draw: ->
    @container.selectAll('li')
      .data( @data )
    .enter().append('li')
      .html (d) => this.template(d)

  update: ->
    @container.selectAll('li')
      .data( @data )
      .html (d) => this.template(d)

To initialize this I call it like so:

jQuery ->
  myLog = new Log 'div#my-log'

This correctly selects the div and renders the message into it.

However, if I try to add log messages in the console:

log.pushData({sender:'test', message:'foo'});

… this does not get rendered to the DOM. If I call log.data in the console I see the data is there, it just didn’t make it to the DOM.

I haven’t been able to spot my mistake, any ideas?

  • 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-16T07:57:36+00:00Added an answer on June 16, 2026 at 7:57 am

    You forgot .enter in update

    update: ->
        @container.selectAll('li')
          .data( @data )
        .enter().append('li')
          .html (d) => this.template(d)
    

    as a note you should also add a .exit to update

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got some markup that looks like this: <div class=button> <span class=image></span> <input
I'm using the RichTextBox to display some readonly text that I have to markup
I have this simple markup: <p> some content here </p> I want to break
I've done some simple string -> DateTime conversions before using DateTime.ParseExact(), but I have
So I have a few properties that I'm using in some sample code I'm
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
I have some code using Lucene that leaves the default conjunction operator as OR,
I have some shaped created using flex primitive classes like ellipse , rectangle, path
I'm using markdown a lot and would like to have a few pages that
I'm trying to filter some XML in JavaScript using E4X and have some specific

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.