javascript - Chartjs 与 Vue,条形图边框半径不起作用

标签 javascript vue.js chart.js vue-chartjs

我有一个名为 BarChart.vue 的组件,我正在尝试让 borderRadius 工作,并且我已经尝试了一切让它工作,但它一直很无助。这是代码:

<script>
//Importing Bar class from the vue-chartjs wrapper
import { Bar } from "vue-chartjs";
//Exporting this so it can be used in other components
export default {
  name: "BarChart",
  extends: Bar,
  props: {
    barData: {
      type: Object,
    },
    barThick: {
      type: Number,
    },
  },
  data() {
    return {
      datacollection: {
        //Data to be represented on x-axis
        labels: this.barData.labels,
        datasets: [
          {
            label: "Ranking",
            backgroundColor: "#e5e5e5",
            barThickness: this.barThick,
            maxBarThickness: 20,
            borderWidth: 1,
            borderSkipped: false,
            borderRadius: 10,
            //Data to be represented on y-axis
            data: this.barData.data,
          },
        ],
      },
      //Chart.js options that controls the appearance of the chart
      options: {
        scales: {
          yAxes: [
            {
              ticks: {
                beginAtZero: true,
                fontColor: "black",
                suggestedMax: 100,
              },
              gridLines: {
                display: true,
              },
            },
          ],
          xAxes: [
            {
              ticks: {
                fontSize: 12,
                fontColor: "black",
                fontFamily: "Roboto",
                maxRotation: 90,
                minRotation: 90,
              },
              gridLines: {
                display: false,
              },
            },
          ],
        },
        legend: {
          display: false,
        },
        responsive: true,
        maintainAspectRatio: false,
      },
    };
  },
  mounted() {
    //renderChart function renders the chart with the datacollection and options object.
    this.renderChart(this.datacollection, this.options);
  },
};
</script>

目前,使用该代码,图表如下所示: enter image description here

我已经搜索了一整天,但没有找到解决方案。

最佳答案

您正在使用库的 V2,borderradius 仅在库的 V3 中引入,因此您需要更新 Chart.js。尽管 Vue 包装器与 Chart.js V3 不兼容,因此您需要自己实现 Chart.js

关于javascript - Chartjs 与 Vue,条形图边框半径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68063910/

相关文章:

javascript - 类内javascript中两种函数声明的区别?

javascript - 如果我上传图片 ,'no files selected' 消息就会显示

javascript - ReactJS:如何立即显示更新后的状态?

php - 即使变量分配有对象数组,v-for 也不起作用

css - html-pdf:如何确保图像不跨越分页符

javascript - 在 div 容器中移动重复模式

javascript - 将 VueJS Prop 传递到 TypeScript 类组件中

javascript - VueJS 中的条件验证

vue.js - Vue 和 Chartjs - 运行一个简单的 vue-chartjs 示例

javascript - AngularJS 图表未正确更新数据