如何调整CHARTJS散点图的大小以匹配PDF大小?

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

我正在为ChartJS的大小调整而挣扎,我现在已经尝试了很多选项...但都很失败。通过以下选项,我至少实现了图表的所需位置和大小。数据都是正确的,但它显示所有压扁....(数据正在从我的后端用handlebars推送...).现在我想得到我的数据“unsquashed”。我将此数据转换为PDF与 puppet 库,但我不相信这是问题,因为我已经看到在某些设置我的数据所需的..先谢谢你了!
Desired CHART look
Actual...

  1. <style>
  2. .container {
  3. display: flex;
  4. justify-content: center;
  5. align-items: center;
  6. }
  7. .test {
  8. width: 100%;
  9. max-width: 400;
  10. height: 225;
  11. }
  12. </style>
  13. <div class="container">
  14. <div class="test">
  15. <canvas id="myChart"></canvas>
  16. </div>
  17. </div>
  1. <script>
  2. document.addEventListener("DOMContentLoaded", function () {
  3. var envelope = {{{envelopeJSON}}};
  4. var utility = {{{utilityJSON}}};
  5. var mb = {{{mbJSON}}};
  6. new Chart("myChart", {
  7. type: "scatter",
  8. data: {
  9. datasets: [
  10. {
  11. label: "{{airplanename}}",
  12. pointRadius: 4,
  13. pointBackgroundColor: "rgb(0, 0, 255)",
  14. data: envelope,
  15. showLine: true,
  16. fill: true,
  17. borderColor: "rgb(0, 150, 255)",
  18. backgroundColor: "rgba(0, 0, 255, 0.2)"
  19. },
  20. {
  21. label: "Utility",
  22. pointRadius: 4,
  23. pointBackgroundColor: "rgb(255, 36, 0)",
  24. data: utility,
  25. showLine: true,
  26. fill: true,
  27. borderColor: "rgb(255, 36, 0, 0.5)",
  28. backgroundColor: "rgba(255, 36, 0, 0.2)"
  29. },
  30. {
  31. label: "Data",
  32. pointRadius: 4,
  33. pointBackgroundColor: "rgb(0, 0, 255)",
  34. data: mb,
  35. showLine: true,
  36. borderColor: "rgb(0, 150, 255)",
  37. }
  38. ]
  39. },
  40. options: {
  41. //responsive: false,
  42. //maintainAspectRatio: false,
  43. legend: { display: false },
  44. scales: {
  45. xAxes: [{ ticks: { min: 80, max: 90 } }],
  46. yAxes: [{ ticks: { min: 1000, max: 2500 } }],
  47. }
  48. }
  49. });
  50. });
  51. </script>

我已经尝试了许多配置,变量:响应和维护方面我已经作为一个评论,我不知道什么配置是适合这个问题....

1tuwyuhd

1tuwyuhd1#

问题是chartJS试图显示从底部开始的动态动画数据,但是当生成PDF时,它需要第一个瞬间,导致图表底部的冻结数据集。:在ChartJS中,您必须设置Options:动画:持续时间:0像这样:

  1. options: {
  2. legend: { display: false },
  3. animation: {
  4. duration: 0
  5. }

相关问题