title: chartjs creating data array dynamically
body: <p>Im creating a Pie chart using chartjs library, and Im wondering how I could represent the values the will be need to render the chart dynamically,</p>
  
  <p>In chartjs.org tutorial the array of data is represented like this</p>
  
  <pre><code>var data = [
          {
             value: 300,
             color:"#F7464A",
             highlight: "#FF5A5E",
             labelColor : 'white',
             labelFontSize : '16'
          },
          {
              value: 100,
              color: "#46BFBD",
              highlight: "#5AD3D1",           
              labelColor : 'white',
              labelFontSize : '16'
          },
          {
              value: 100,
              color: "#FDB45C",
              highlight: "#FFC870",
              labelColor : 'white',
              labelFontSize : '16'
          }
      ]
  </code></pre>
  
  <p>and data will be pass as an argument to render the chart</p>
  
  <pre><code>new Chart(ctx).Pie(data);
  </code></pre>
  
  <p>this then renders a chart with 3 partitions:
  <a href="https://i.stack.imgur.com/W4q2Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W4q2Q.png" alt="enter image description here"></a></p>
  
  <p>But say I want to render X partitions, how can i make an array of data?</p>
  
  <p>would I be able to do in a loop and append it to data?</p>
  
  <p>Code so far:</p>
  
  <pre><code>function drawPie(ctx){
  
              var newopts = {
                  inGraphDataShow: true,
                  inGraphDataRadiusPosition: 2,
                  inGraphDataFontColor: 'white',
              }
  
              //=========
              // this should be dynamic (data will come the parameter)
              //==========
              var data = [
              {
                  value: 300,
                  color:"#F7464A",
                  highlight: "#FF5A5E",
  
                  labelColor : 'white',
                   labelFontSize : '16'
              },
              {
                  value: 100,
                  color: "#46BFBD",
                  highlight: "#5AD3D1",           
  
                  labelColor : 'white',
                  labelFontSize : '16'
              },
              {
                  value: 100,
                  color: "#FDB45C",
                  highlight: "#FFC870",
  
                   labelColor : 'white',
                   labelFontSize : '16'
              }
          ]
  
          new Chart(ctx).Pie(data, newopts);
  
  } 
  </code></pre>