在 bulma 全高英雄中显示 chartjs 图表

Displaying a chartjs chart within a bulma full height hero

我正在尝试在 bulma 全屏英雄部分中显示 chartjs 图表。期望的效果是该部分将占用可用的浏览器 space。我还需要图表保持响应。

如果能够在图表上方添加一些文字、标题和副标题也很好。

下面的代码有效,但 chartjs 变为 non-responsive。

<!-- Section: First Chart -->
<section class="hero is-fullheight">
  <div class="hero-body">
    <div class="container">
      <div>
        <canvas id="chart"></canvas>
      </div>
    </div>
  </div>
</section>

如果我尝试添加标题,我们会溢出整个高度:

<!-- Section: First Chart -->
<section class="hero is-fullheight">
  <div class="hero-body">
    <div class="container">
      <h1 class="title has-text-grey-dark">
        My title
      </h1>
      <canvas id="chart"></canvas>
    </div>
  </div>
</section>

请试试这个。我认为您不需要容器并通过 chart.js

添加标题

如果有帮助请告诉我。

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bulma@0.8.1/css/bulma.min.css" rel="stylesheet"/>

<section class="hero is-primary is-fullheight">
  <div class="hero-body">
    <canvas id="chart"></canvas>
  </div>
</section>
<script>
var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
                'rgba(54, 162, 235, 0.2)',
                'rgba(255, 206, 86, 0.2)',
                'rgba(75, 192, 192, 0.2)',
                'rgba(153, 102, 255, 0.2)',
                'rgba(255, 159, 64, 0.2)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        },
        title: {
         display: true,
          text: 'Custom Chart Title',
          fontSize: 24,
          fontColor: '#fff'
        }
    }
});
</script>

对于任何想做同样事情的人

    <!-- Section: First Chart -->
    <section class="hero is-fullheight">
      <div>
      <div class="hero-body">
        <div class="container">
        <h1>Title</h1>
        <canvas id="chart"></canvas>
      </div>
      </div>
    </div>
    </section>