为了账号安全,请及时绑定邮箱和手机立即绑定

Chart.js 雷达图刻度隐藏在图表后面

Chart.js 雷达图刻度隐藏在图表后面

天涯尽头无女友 2022-12-02 17:02:40
是否可以将 Chart.js 雷达图的“刻度”带到前台,以便它们位于图表本身的顶部?我在官方文档中没有看到与此问题相关的任何内容。呈现这个的方法:const chart = new Chart(ctx, {  type: 'polarArea',        data: {    labels: ['Silver', 'Palladium', 'Platinum', 'Gold'],    datasets: [      {        label: 'Points',        pointRotation: 45,        backgroundColor: [          color(this.chartColors.grey).rgbString(),          color(this.chartColors.green).rgbString(),          color(this.chartColors.blue).rgbString(),          color(this.chartColors.yellow).rgbString(),        ],        data: [0, 0, 0, 0],        borderWidth: 0,        pointBackgroundColor: 'rgba(0, 0, 0, 1)'      }    ],  },  options: {    responsive: true,    animation: {      animateRotate: true    },    layout: {      padding: {          left: 0,          right: 0,          top: 0,          bottom: 0      }    },    scale: {      ticks: {        fontColor: '#000000',        mirror: true,      }    },    legend: {      position: 'top'    },  }});一种解决方法是使这些填充颜色透明,如下所示:color(this.chartColors.yellow).alpha(0.5).rgbString(),......这样滴答声就会在某种程度上可以接受地看到。但是,我宁愿让它们完全饱和。在此先感谢您的任何建议。
查看完整描述

1 回答

?
MMTTMM

TA贡献1869条经验 获得超4个赞

您可以按照此处记录scale.ticks.z的那样定义该选项。

scale: {

  ticks: {

    ...

    z: 1

  }

},

刻度层的 z-index。在图表区域绘制刻度时很有用。值 <= 0 绘制在数据集下方,> 0 绘制在顶部。


请在下面查看您修改后的代码:


const chart = new Chart('myChart', {

  type: 'polarArea',

        data: {

    labels: ['Silver', 'Palladium', 'Platinum', 'Gold'],

    datasets: [

      {

        label: 'Points',

        pointRotation: 45,

        backgroundColor: ['grey', 'green', 'blue', 'yellow'],

        data: [3, 4, 8, 9],

        borderWidth: 0,

        pointBackgroundColor: 'rgba(0, 0, 0, 1)'

      }

    ]

  },

  options: {

    responsive: true,

    animation: {

      animateRotate: true

    },

    layout: {

      padding: {

          left: 0,

          right: 0,

          top: 0,

          bottom: 0

      }

    },

    scale: {

      ticks: {

        fontColor: '#000000',

        mirror: true,

        z: 1

      }

    },

    legend: {

      position: 'top'

    }

  }

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>

<canvas id="myChart" height="100"></canvas>


查看完整回答
反对 回复 2022-12-02
  • 1 回答
  • 0 关注
  • 111 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信