Chart.js最小值最大值不工作,无法在值更改时禁用缩放

yws3nbqq  于 2023-03-18  发布在  Chart.js
关注(0)|答案(1)|浏览(162)

我试图创建一个有两个移动点的静态图表。我不知道如何强制图表不缩放,因为我的值正在变化,同时给y轴520-780和x轴21-37的值。
这是我的代码:

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'scatter',
    data: {
        datasets: [{
            label: "Mass & Balance Envelope",
            data: [],
            backgroundColor: 'red'
        }]
    },
    options: {
        tooltips: {
            backgroundColor: "rgba(0, 0, 0, 0.8)",
            titleFontSize: 16,
            bodyFontSize: 14
          },
          display: false,
          scales: {
            x: [{
              type: 'linear',
              position: 'bottom',
              ticks: {
                min: 21,
                max: 37
              }
            }],
            y: [{
              type: 'linear',
              position: 'left',
              ticks: {
                min: 520,
                max: 780
              }
            }]
          }
        }      
  });

setInterval(function() {
    var dot1_x = vypocet_vahy_lietadla_funkcia();
    var dot1_y = vypocet_pozicie_taziska_SAT_funkcia();
    var dot2_x = vypocet_vahy_lietadla_0fuel_funkcia();
    var dot2_y = vypocet_pozicie_taziska_SAT_0fuel_funkcia();
    chart.data.datasets[0].data = [
        {x: dot1_y, y: dot1_x, label: "TO Weight and Balance"},
        {x: dot2_y, y: dot2_x, label: "0 Fuel Weight and Balance"}    
    ];
    chart.update();
}, 1000);
zysjyyx4

zysjyyx41#

这修复了它,因为我使用Chart.js 4+

options: {
    tooltips: {
      backgroundColor: "rgba(0, 0, 0, 0.8)",
      titleFontSize: 16,
      bodyFontSize: 14
    },
    maintainAspectRatio: false,
    scales: {
      x: {
        type: 'linear',
        position: 'bottom',
        suggestedMin: 21,
        suggestedMax: 37
      },
      y: {
        type: 'linear',
        position: 'bottom',
        suggestedMin: 520,
        suggestedMax: 780
      }
    }
  },

相关问题