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

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

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

  1. var ctx = document.getElementById('myChart').getContext('2d');
  2. var chart = new Chart(ctx, {
  3. type: 'scatter',
  4. data: {
  5. datasets: [{
  6. label: "Mass & Balance Envelope",
  7. data: [],
  8. backgroundColor: 'red'
  9. }]
  10. },
  11. options: {
  12. tooltips: {
  13. backgroundColor: "rgba(0, 0, 0, 0.8)",
  14. titleFontSize: 16,
  15. bodyFontSize: 14
  16. },
  17. display: false,
  18. scales: {
  19. x: [{
  20. type: 'linear',
  21. position: 'bottom',
  22. ticks: {
  23. min: 21,
  24. max: 37
  25. }
  26. }],
  27. y: [{
  28. type: 'linear',
  29. position: 'left',
  30. ticks: {
  31. min: 520,
  32. max: 780
  33. }
  34. }]
  35. }
  36. }
  37. });
  38. setInterval(function() {
  39. var dot1_x = vypocet_vahy_lietadla_funkcia();
  40. var dot1_y = vypocet_pozicie_taziska_SAT_funkcia();
  41. var dot2_x = vypocet_vahy_lietadla_0fuel_funkcia();
  42. var dot2_y = vypocet_pozicie_taziska_SAT_0fuel_funkcia();
  43. chart.data.datasets[0].data = [
  44. {x: dot1_y, y: dot1_x, label: "TO Weight and Balance"},
  45. {x: dot2_y, y: dot2_x, label: "0 Fuel Weight and Balance"}
  46. ];
  47. chart.update();
  48. }, 1000);
zysjyyx4

zysjyyx41#

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

  1. options: {
  2. tooltips: {
  3. backgroundColor: "rgba(0, 0, 0, 0.8)",
  4. titleFontSize: 16,
  5. bodyFontSize: 14
  6. },
  7. maintainAspectRatio: false,
  8. scales: {
  9. x: {
  10. type: 'linear',
  11. position: 'bottom',
  12. suggestedMin: 21,
  13. suggestedMax: 37
  14. },
  15. y: {
  16. type: 'linear',
  17. position: 'bottom',
  18. suggestedMin: 520,
  19. suggestedMax: 780
  20. }
  21. }
  22. },
展开查看全部

相关问题