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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:44:36+00:00 2026-05-23T01:44:36+00:00

I’m using mootools 1.2 in a page where I’m loading a js graph into

  • 0

I’m using mootools 1.2 in a page where I’m loading a js graph into a div that is itself in a table cell. The graph loads properly, but it’s quite a lot smaller than the width of the cell (the graph script is meant to generate a graph the same size as the div).

My question is: how can you set the size of the div based on the size of its parent container, dynamically (rather than setting a fixed pixel width of the div).

I’d like to set the size of the div with mootools setStyle on domready, like this (all wrapped in a domready block):

var divwidth    = $('my_chart').offsetParent.offsetWidth;
var divheight   = $('my_chart').offsetParent.offsetHeight;
$('my_chart').setStyle('width', divwidth);
$('my_chart').setStyle('height', divheight);

g           = new Dygraph($('my_chart'), data);

When I run the page without the setStyle stuff, it works, but the div returns a width of 480 when I execute $('my_chart').getStyle('width'); from a js console. However, the $('my_chart').offsetParent.offsetWidth from the same console returns 1100.

The problem is that when I try to set the div size using the code above, it throws an error:
Uncaught TypeError: Cannot read property 'offsetWidth' of null I assume because the div is not drawn yet?

Edit to add: if I set the width of the my_chart div to “auto”, I get an error Uncaught TypeError: Cannot read property 'length' of undefined from the graph script.

Thanks for any help.

  • 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-05-23T01:44:36+00:00Added an answer on May 23, 2026 at 1:44 am

    http://jsfiddle.net/dimitar/c7GTA/

    jsfiddle right back at you.

    the problem is that this tool uses canvas. and it kind if needs to set the canvas width to a set value.

    var c = document.id("mychart");
    c.setStyle("width", c.getParent().getSize().x);
    
    new Dygraph(document.id("mychart"),
    "Date,Temperature\n" + "2008-05-07,75\n" + "2008-05-08,70\n" + "2008-05-09,80\n"
    );
    

    this works fine but table resize will make it look odd.
    use .getSize() which returns an object with x and y properties for width and height. don’t trust computations based upon css/style.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.