-1

I have been trying to display average line using chart.js, but I do not know how to do that.

This is my code:

var myChart = {
        type: 'line',
        data: {
          labels: MONTHS,  // array
          datasets: [{
            label: "Temperature",
            fill: false,
            backgroundColor: chartColors.red,
            borderColor: chartColors.red,
            data: tempInfo,  //array [1,2,3,4,5,6,7]         
          }]
        },
        options: {
          responsive: true,
          title: {
            display: true,
            text: 'Farm Health Monitor'
          },
          tooltips: {
            mode: 'label',
          },
          hover: {
            mode: 'nearest',
            intersect: true
          },
          scales: {
            xAxes: [{
              display: true,
              scaleLabel: {
                display: true,
                labelString: 'Month'
              }
            }],
            yAxes: [{
              display: true,
              scaleLabel: {
                display: true,
                labelString: 'Value'
              }
            }]
          }
        }
      };
pushkin
  • 9,575
  • 15
  • 51
  • 95
Gil
  • 105
  • 2
  • 5
  • 12
  • Does this answer your question? [Draw horizontal line on chart in chart.js on v2](https://stackoverflow.com/questions/42691873/draw-horizontal-line-on-chart-in-chart-js-on-v2) – Pipo Dec 08 '19 at 08:52
  • basically you'll need a second dataset, that only contains some of the mains dataset entries, but with somehow averaged values...how to calculate these, thats another question... – benzkji Sep 29 '20 at 09:25

1 Answers1

-5

Just use Mathjs library site is http://mathjs.org.

And use the method : math.mean(yourArray) <-- put your Array in

I hope it will be helpful to you.

Gil
  • 105
  • 2
  • 5
  • 12