Home forums Using CanvasJS Resetting width to auto? (100%)

This topic contains 1 reply, has 2 voices, and was last updated by  Sanjoy 2 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15986

    thumbs
    Member

    I’m trying to use a variable to set the width within a chart, i.e.

    var chart = new CanvasJS.Chart("myChart", {
    	width: determinedwidth,
    

    …in which the variable determinedwidth is set based on the size of the x-axis (these are dates.) So a chart with 10 years of data might have a determined width of 5000px placed in a scrolling div so things are spaced apart enough to be legible.

    That said, anything less than a year lets say I’d like to just fill the container like the default behavior – but I can’t figure out how to make the ‘determinedwidth’ variable in this case just go back to ‘normal’. Percentages don’t work, and I can’t seem to use a condition within the var chart code to only set the width if the variable exists. I suppose I could use a lot of redundant code to set the var chart data one way or another (one with width set if determinedwidth exists, and one without) but I’m hoping there’s a better way?

    Long story short, is there a way to ‘undeclare’ the width since I can’t use percentages?

    Thanks!

    #15989

    Sanjoy
    Moderator

    thumbs,

    Can you please create a jsfiddle reproducing the case so that we can understand it better and help you out.


    Sanjoy Debnath
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.