'change fillColor in JavaScript LineChart between two points

I've created a dynamic Line Chart that every 2 seconds generates a new (random) value. Now I want that this chart changes the color of the area under the curve using the colors that I've specified in fillColor parameter. The color should change (if it really changes) only between two points not on the entire chart.

I'm stucked at this point. enter image description here

I'm not a JavaScript developer and i'm not able to find a solution to this problem. There's someone that could help?

Here is the complete code:

$(document).ready(function() {
    var ctx = document.getElementById("myChart").getContext("2d");
  
    var data = {
      labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October"],
      datasets: [{
        label: "Time Series",
        strokeColor: "rgba(0,0,0,1)",
        pointColor: "rgba(0,0,0,1)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(220,220,220,1)",
        data: [65, 59, 80, 81, 56, 55, 40, 0, 0, -15],
        fillColor: ["rgba(222, 145, 14)", "rgba(222, 145, 14)", "rgba(222, 145, 14)", "rgba(63, 215, 32)", "rgba(63, 215, 32)", "rgba(63, 215, 32)", "rgba(63, 215, 32)", "rgba(242, 8, 16, 0.7)", "rgba(242, 8, 16, 0.7)", "rgba(242, 8, 16, 0.7)"]
      }]
    };

    var options = {
      animation: false,
      scaleOverride: true,
      scaleSteps: 10,
      scaleStepWidth: 10,
      scaleStartValue: 0
    };

  
    var myLineChart = new Chart(ctx).Line(data, options);
  
    setInterval(function() {
      setData(data.datasets[0].data);
      setLabels(data.labels);
      setState(data.datasets[0].fillColor);
  
      var myLineChart = new Chart(ctx).Line(data, options);
    }, 2000);
  
    function setLabels(labels) {
      var nextMonthIndex = months.indexOf(labels[labels.length - 1]) + 1;
      var nextMonthName = months[nextMonthIndex] != undefined ? months[nextMonthIndex] : "January";
      labels.push(nextMonthName);
      labels.shift();
    }
  
    function setData(data) {
      data.push(Math.floor(Math.random() * 100) + 1);
      data.shift();
    }

    // new Function
    function setState(data) {
        data.push(Math.floor(Math.random() * data.length)); 
        data.shift();
    }
    
    function convertMonthNameToNumber(monthName) {
      var myDate = new Date(monthName + " 1, 2016");
      var monthDigit = myDate.getMonth();
      return isNaN(monthDigit) ? 0 : (monthDigit + 1);
    }
    
    var months = ["January", "February", "March", "April", "May", "June",
      "July", "August", "September", "October", "November", "December"
    ];
  
  });

Thanks for the help to everyone!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source