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

问题描述 投票:0回答:1

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

也可以在图表上方添加一些文本,标题和副标题。

下面的代码有效,但是chartjs变得没有响应。

<!-- 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>
css chart.js bulma
1个回答
0
投票

请尝试这个。我认为您不需要容器并通过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/[email protected]/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>
© www.soinside.com 2019 - 2024. All rights reserved.