Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript chart.js-轴选项问题-我做错了什么?_Javascript_Chart.js - Fatal编程技术网

Javascript chart.js-轴选项问题-我做错了什么?

Javascript chart.js-轴选项问题-我做错了什么?,javascript,chart.js,Javascript,Chart.js,我是chart.js的新手,设置选项让我感到困惑 就我的一生而言,我似乎不知道如何将我的xAxis标签(unix时间戳(秒))格式化为人类可读的时间 其次,我不能让yAxis设置最小值和最大值 我相信这是一个很简单的问题,在座的人会马上意识到。我感谢你的帮助 以下是代码: var FV201_ctx = document.getElementById('FV201_chart').getContext('2d'); var FV201_cfg = { type: 'li

我是chart.js的新手,设置选项让我感到困惑

就我的一生而言,我似乎不知道如何将我的xAxis标签(unix时间戳(秒))格式化为人类可读的时间

其次,我不能让yAxis设置最小值和最大值

我相信这是一个很简单的问题,在座的人会马上意识到。我感谢你的帮助

以下是代码:

var FV201_ctx = document.getElementById('FV201_chart').getContext('2d');
    var FV201_cfg = {
        type: 'line',
        data: {
          labels: FV201_timestamps,
          datasets: [
            {
              label: 'temps',
              data: FV201_temps,
              type: 'line',
              fill: false
            }
          ]
         },
          options: {
            title: {text: 'my chart', display: false},
            scales: {
                xAxes: [{
                    type: 'time',
                    time: {
                        unit: 'second',
                        displayFormats: { second: 'hh:mm:ss' },
                        parser: function(foo) { return moment(foo,'X'); }
                    }
                }],
                yAxes: [{
                  ticks: {
                     suggestedMin: 28.5,
                     suggestedMax: 29,
                     stepSize: 0.1
                  }
              }]
            },
          }
    };
    var FV201_chart = new Chart(FV201_ctx, FV201_cfg);
    FV201_chart.update();
  • 选项
    不应位于
    数据
    对象内
  • x轴和y轴应为阵列类型

  • 谢谢你的代码,它对我很有用。我希望不必对时间戳进行太多的重新格式化,因为将显示许多图表,并且它们将不断更新。我一直在尝试让时间功能按运行,并认为我可以只添加一个格式化程序,但我似乎无法让它运行。@blonoz我现在明白了。我已经根据他们的文档进行了更新。这对我有用,太棒了!谢谢你,伙计!
    var FV201_ctx = document.getElementById('FV201_chart').getContext('2d');
        var FV201_cfg = {
            type: 'line',
            data: {
              labels: FV201_timestamps,
              datasets: [
                {
                  label: 'temps',
                  data: FV201_temps,
                  type: 'line',
                  fill: false
                }
              ]
             },
              options: {
                title: {text: 'my chart', display: false},
                scales: {
                    xAxes: [{
                        type: 'time',
                        time: {
                            unit: 'second',
                            displayFormats: { second: 'hh:mm:ss' },
                            parser: function(foo) { return moment(foo,'X'); }
                        }
                    }],
                    yAxes: [{
                      ticks: {
                         suggestedMin: 28.5,
                         suggestedMax: 29,
                         stepSize: 0.1
                      }
                  }]
                },
              }
        };
        var FV201_chart = new Chart(FV201_ctx, FV201_cfg);
        FV201_chart.update();