【问题标题】:How is it possible to make curved bar chart or curved column charts in chart.js?如何在 chart.js 中制作曲线条形图或曲线柱形图?
【发布时间】:2020-03-14 06:42:55
【问题描述】:

我们正在尝试创建类似于下图的曲线柱,在 chart.js 中看起来不可能

对此有何建议?

【问题讨论】:

    标签: javascript chart.js chart.js2 jscharts


    【解决方案1】:

    您可以使用line 图表来执行此操作,如下面的代码示例所示,需要进一步改进才能获得您期望的结果。

    new Chart(document.getElementById('myChart'), {
        type: 'line',
        data: {
            labels: [1, 2, 3, 4, 5, 6, 7],
            datasets: [
              {
                  data: [0, 5, 0, 0, 0, 0, 0],
                  fill: true,
                  backgroundColor: 'rgb(255, 0, 0, 0.7)',
                  backgroundColor: 'rgb(255, 0, 0, 0.7)',
                  lineTension: 0.4,
                  pointHitRadius: 0
              },
              {
                  data: [0, 0, 9, 0, 0, 0, 0],
                  fill: true,
                  backgroundColor: 'rgb(255,165,0, 0.7)',
                  backgroundColor: 'rgb(255,165,0, 0.7)',
                  lineTension: 0.6,
                  pointHitRadius: 0
              },
              {
                  data: [0, 0, 0, 6, 0, 0, 0],
                  fill: true,
                  backgroundColor: 'rgb(255, 215, 0, 0.7)',
                  backgroundColor: 'rgb(255, 215, 0, 0.7)',
                  lineTension: 0.6,
                  pointHitRadius: 0
              },
              {
                  data: [0, 0, 0, 0, 5, 0, 0],
                  fill: true,
                  backgroundColor: 'rgb(59, 161, 151, 0.7)',
                  backgroundColor: 'rgb(59, 161, 151, 0.7)',
                  lineTension: 0.6,
                  pointHitRadius: 0
              },
              {
                  data: [0, 0, 0, 0, 0, 4, 0],
                  fill: true,
                  backgroundColor: 'rgb(100, 100, 100, 0.7)',
                  backgroundColor: 'rgb(100, 100, 100, 0.7)',
                  lineTension: 0.4,
                  pointHitRadius: 0
              }
            ]
        },
        options: {
            responsive: true,
            elements: {
              point:{
                radius: 0
              }
            },
            title: {
                display: false,
            },
            legend: {
                display: false
            },
            tooltips: {
                display: false
            },
            scales: {
                yAxes: [{
                   ticks: {
                     display: false
                   },
                   gridLines: {
                     display: false
                   }
                }],
                xAxes: [{
                   ticks: {
                     display: false
                   },
                   gridLines: {
                     display: false
                   }
                }],
            }
        }
    });
    canvas {
      max-width: 300px;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
    <canvas id="myChart" height="200"></canvas>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多