javascript - Chartjs 无边框条形图

标签 javascript chart.js

我正在尝试使用 Chartjs 构建一个条形图,其中相邻条形之间不应有空格。我遇到的问题是我没有摆脱栏之间的边界: Bars with borders

这是我的配置:

new Chart($('#weekly-availabilities-chart'), {
  type: 'bar',
  data: {
  labels: ...,
  datasets: [
    {
      backgroundColor: 'rgba(153, 193, 72, 0.4)',
      label: 'label a',
      borderWidth: 0,
      data: dataset_1
    }, {
      backgroundColor: 'rgba(13, 39, 73, 0.4)',
      label: 'label b',
      borderWidth: 0,
      data: dataset_2
    }
  ]
},
  options: {
  scales: {
    xAxes: [
      {
        barPercentage: 1,
        categoryPercentage: 1,
        gridLines: {
          display: false
        }
      }
    ],
    yAxes: [
      {
        stacked: true,
        gridLines: {
          color: 'rgba(0,0,0,0.05)'
        },
        ticks: {
          beginAtZero: true,
          max: 40
        }
      }
    ]
  }
}
});

最佳答案

使用borderWidth: 0在你的数据集中。

datasets: [
  {
    backgroundColor: 'rgba(153, 193, 72, 0.4)',
    label: 'label a',
    data: dataset_1,
    borderWidth: 0
  }, {
    backgroundColor: 'rgba(13, 39, 73, 0.4)',
    label: 'label b',
    data: dataset_2,
    borderWidth: 0
  }
]

关于javascript - Chartjs 无边框条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44153999/

相关文章:

Javascript 函数不打开嵌套可折叠

javascript - 如何在for循环中初始化数组?

javascript - 使用简单的网络表单计算平均值

javascript - jshint 无法识别 devel

javascript - 如何从日期时间中删除时间?

javascript - 类型错误 : Cannot read property 'defaults' of undefined when using the react wrapper of chartjs

javascript - ChartJs Canvas 在更改图形类型时显示以前的图形

javascript - Chart.js 条形图 : show tooltip on label hover

javascript - 从下拉选择更新图表

chart.js - Chartjs 折线图只有一个点 - 如何居中