javascript Chart.js 响应式选项 - 图表未填充容器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27334757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 07:21:18  来源:igfitidea点击:

Chart.js responsive option - Chart not filling container

javascriptjquerychartschart.js

提问by Abram

Check out this fiddle. What am I doing wrong? Isn't the responsive option supposed to force the chart to fill it's container?

看看这个小提琴。我究竟做错了什么?响应式选项不是应该强制图表填充它的容器吗?

Chart.js - Chart not filling container

Chart.js - 图表未填充容器

<div style="width:800px; height:400px;">
  <canvas id="myChart"></canvas>
</div>


<script>
  $( document ).ready(function() {

  var data = {
      labels: ["January", "February", "March", "April", "May", "June", "July"],
      datasets: [
          {
              label: "My First dataset",
              fillColor: "rgba(220,220,220,0.2)",
              strokeColor: "rgba(220,220,220,1)",
              pointColor: "rgba(220,220,220,1)",
              pointStrokeColor: "#fff",
              pointHighlightFill: "#fff",
              pointHighlightStroke: "rgba(220,220,220,1)",
              data: [65, 59, 80, 81, 56, 55, 40]
          },
          {
              label: "My Second dataset",
              fillColor: "rgba(151,187,205,0.2)",
              strokeColor: "rgba(151,187,205,1)",
              pointColor: "rgba(151,187,205,1)",
              pointStrokeColor: "#fff",
              pointHighlightFill: "#fff",
              pointHighlightStroke: "rgba(151,187,205,1)",
              data: [28, 48, 40, 19, 86, 27, 90]
          }
      ]
  };
  options = {
    responsive: true
  };
  // Get context with jQuery - using jQuery's .get() method.
  var ctx = $("#myChart").get(0).getContext("2d");
  // This will get the first returned node in the jQuery collection.
  var myLineChart = new Chart(ctx).Line(data, options);
  });
</script>

采纳答案by Abram

Sorry about this, but I realized that the version I was using was outdated. For future reference, I found an up to date version of chart.js here.

对此很抱歉,但我意识到我使用的版本已过时。为了将来参考,我在这里找到了 chart.js 的最新版本。

//cdn.jsdelivr.net/chart.js/1.0.1-beta.4/Chart.min.js

Hereis the updated fiddle

是更新的小提琴