Skip to content

how to pass variables to Chart() ? #10096

Answered by LeeLenaleee
chk1xn asked this question in Q&A
Discussion options

You must be logged in to vote

You can just pass a variable with your calculated aspectRatio like so:

const max = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
console.log(max)
const aspectRatio = max / max // Calculate correct aspectRatio here

const options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        borderWidth: 1
      }
    ]
  },
  options: {
    aspectRatio: aspectRatio
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@chk1xn
Comment options

Answer selected by chk1xn
Comment options

You must be logged in to vote
2 replies
@kurkle
Comment options

@LeeLenaleee
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants