title: Add dynamic dataset to chart.js
body: <p>I'm trying to add lines to a chart.js chart dynamically where I don't know how many datasets I have
  I've been banged my head on this for two days now...</p>
  
  <p>I have a list containing Year, Month and Value:</p>
  
  <pre><code>    public int Month { get; set; }
      public int Year { get; set; }
      public int Value { get; set; }
  </code></pre>
  
  <p>My HTML is just a canvas for the chart:</p>
  
  <pre><code>&lt;div&gt;
  &lt;canvas id="myChart"&gt; &lt;/canvas&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I populate the chart like this:</p>
  
  <pre><code> var dataList = [];
      var lableList = [];
      @foreach (var dataInput in Model.TurnoverByReservation)
      {
  
          @:dataList.push("@dataInput.Value");
          @:lableList.push("@dataInput.MonthName");
      }
  
      var ctx = document.getElementById("myChart");
      var myChart = new Chart(ctx, {
          type: 'line',
          data: {
              labels: lableList,
              datasets: [
                  {
                      label: 'Booking value',
                      data: dataList,
                      backgroundColor: backgroundColors,
                      borderColor: borderColors,
                      borderWidth: 1
                  }
              ]
          },
          options: {
              scales: {
                  yAxes: [
                      {
                          ticks: {
                              beginAtZero: true,
                              callback: function(value, index, values) {
                                  if (parseInt(value) &gt;= 1000) {
                                      return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                                  } else {
                                      return value;
                                  }
                              }
                          }
                      }
                  ]
              }
          }
      });
  </code></pre>
  
  <p>So the question is; how can I add different datasets to the chart so that I can use something like this?</p>
  
  <pre><code>@foreach (var year in Model.TurnoverByReservation.OrderBy(x =&gt;x.Month).GroupBy(x =&gt; x.Year))
  {
  foreach (var value in year)
   {
      //Add the value to the dataset, somehow...
   }
  }
  </code></pre>