title: How to add a line of best fit (trendline) to a scatter plot in CanvasJS?
body: <p>I have scatter graph which contains a lot of data, too much to display to a user. I would like to add a line of best fit or 'trendline' to the graph to show the trend and make the scatter plots invisible. 
  My data is stored in an external JSON file in the format:</p>
  
  <pre><code>{
      "X" : [1,2,3,4,5,6,7,8,9...],
      "Y" : [1,2,3,4,5,6,7,8,9...]
  }
  </code></pre>
  
  <p>And I am displaying my data using this code:</p>
  
  <pre><code>function addData(data){
    console.log("Adding data");
    var gradeMaxLength = 0; 
  
    for( var i = 0; i &lt; data.length; i++ ){
      if( gradeMaxLength &lt; data[i].grade.length ){
        gradeMaxLength = data[i].grade.length;
      }
    }
  
    // addding datSeries
    for( var j = 0; j &lt; gradeMaxLength; j++ ){
      chart.options.data.push({
        type:"scatter",
        dataPoints:[]
      });
    }
  
    // adding dataPoints
    for( var k = 0; k &lt; data.length; k++ ){
      for( var l = 0; l &lt; gradeMaxLength; l++ ){
        chart.options.data[l].dataPoints.push({
          x: data[k].present[l],
          y: data[k].grade[l]
        }
      );
    }
  }
  chart.render();
  }
  </code></pre>
  
  <p>Is there a way I can add a line of best fit to my graph, of which I have included a photo of below?</p>
  
  <p><a href="https://i.stack.imgur.com/vEsQh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vEsQh.png" alt="Graph"></a></p>