【问题标题】:How to display average line in chart.js如何在chart.js中显示平均线
【发布时间】:2018-05-19 06:24:13
【问题描述】:

我一直在尝试使用 chart.js 显示平均线,但我不知道该怎么做。

这是我的代码:

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'
              }
            }]
          }
        }
      };

【问题讨论】:

标签: javascript arrays chart.js average display


【解决方案1】:

只要使用 Mathjs 库站点是http://mathjs.org

并使用方法:math.mean(yourArray)

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2013-03-24
    • 1970-01-01
    • 2012-08-31
    • 2017-05-25
    • 1970-01-01
    • 2011-01-30
    • 2021-06-25
    • 2022-06-30
    • 2015-04-08
    相关资源
    最近更新 更多